I'm not sure what the problem is but this code should get you what you want:


public function getCategoriesWithLatest()
{
        return $this->Category->find(
                'all',
                array(
                        'fields' => array(
                                'Category.id',
                                'Category.name'
                        ),
                        'contain' => array(
                                'Post' => array(
                                        'fields' => array(
                                                'Post.id',
                                                'Post.title'
                                        ),
                                        'limit' => 1,
                                        'order' => array(
                                                'Post.created' => 'DESC'
                                        )
                                )
                        )
                )
        );
}

Put it in the Post model.

On Wed, Dec 26, 2012 at 9:18 PM, Fernando Queiroz <[email protected]> wrote:
> Hello friends,
>
> I have a doubt, I am working with two tables categories and posts on a given
> query want to display in my home only 1 post from each category, the last.
> As if it was the home of a forum.
>
> I am able to display one post from each category, but they can not be the
> last registered.
>
> Follow my code using group by and order by together
> http://bin.cakephp.org/saved/84693
>
> Does anyone by chance has gone through this problem?
>
> Thank you in advance!
>
>
> --
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>
> ---
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
Visit this group at http://groups.google.com/group/cake-php?hl=en.


Reply via email to