Tuesday, February 7, 2012

Help making a query to select all Posts which have lots of Comments

Hello, I have a Post model with each Post can have many Comments and
each Comment belongs to a Post.

What I'm trying to do is select only Posts which have 5 more comments
using Pagination.

I'm confused on how to construct this query and how to do it using
Pagination. I know I need to get a count of how many comments each
post has, but how with the paginator?

Can anyone point me in the right direction, something like
Post.comments > 5, this doesn't work obviously.

$this->Post->recursive = 1;
$this->paginate = array(
'conditions'=>array(
'status'=>'published',
'Post.comments > 5'
),
'limit'=>10,
'order'=>'published_on DESC'
);
$this->set('posts', $this->paginate('Post'));

Thanks.

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: