Hello, You could do it easily with counterCache
http://book.cakephp.org/1.3/view/1033/counterCache-Cache-your-count Andras Kende http://www.kende.com On Feb 7, 2012, at 5:22 PM, andrewperk wrote: > 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 > [email protected] For more options, visit this group at > http://groups.google.com/group/cake-php -- 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 [email protected] For more options, visit this group at http://groups.google.com/group/cake-php
