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

2012-02-07 Thread andrewperk
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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


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

2012-02-07 Thread andrewperk
I made a typo in the 2nd paragraph. I meant:

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

On Feb 7, 3:22 pm, andrewperk andrewp...@gmail.com 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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


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

2012-02-07 Thread Andras Kende
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
 cake-php+unsubscr...@googlegroups.com 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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php