Wednesday, March 25, 2009

Re: COUNT HABTM whith condition

On Mar 25, 8:47 pm, donnerbeil <donnerb...@googlemail.com> wrote:
> All I need is a way to only count the posts with post.created>
> [given_date]

Try:
$users = $this->User->find('all', array(
'conditions' => array('Post.created >' => $someDate),
'recursive' => 0, //int
'fields' => array('*','COUNT(PostsUser.post_id) AS num'),
'group' => 'User.id',
'order' => 'num DESC',
'limit' => 10 //I onlyneed the top10
));

.... substituting $someDate with the date you're wanting.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: