1

I would like generate list like day=>title:

$news = $this->News->find('list', array(
    'conditions' => array(
        'News.created LIKE' => '2008-09%'),
    'fields' => array(
        'DAY(News.created) AS day',
        'News.name'),
    'recursive' => -1));

...but doesn't work, why?

Function SUBSTR/SUBSTRING also...

When I use find with 'all' property, the function DAY works good!

2
  • What does "doesn't work" mean? What happens and what do you expect to happen? You have to be more specific, otherwise we won't be able to help you. Commented May 13, 2012 at 0:54
  • I know the question is already answered, but even "Generate incorrect list" is not really helpful. How should we know what "incorrect" is in this case? It is as useful as saying "does not work". You should provide an example of the list you get and the list you want. Keep that in mind for future questions. Commented May 13, 2012 at 18:11

1 Answer 1

2

It won't work because DAY(News.created) is a computed value, but it will probably work if you make it a virtual field.

Note that when you use 'all', each row on the results array will have a [0][day] key for that value, instead of [News][day]. This means Cake won't recognize it as a field from model News, and that's why you can't use it with 'list'.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.