Thank you so much! I'm still not entirely sure about how it works, but
I'll be reading up on bindModel :)
I've taken a look at counterCache and yes, it looks much easier. I'll
consider using it instead.

Again - thanks!

On 20 Maj, 15:41, grigri <[EMAIL PROTECTED]> wrote:
> $this->Activity->bindModel(array(
>   'hasOne' => array(
>     'TotalUsers' => array(
>       'className' => 'User',
>       'fields' => 'COUNT(TotalUsers.id) AS num_users'
>     )
>   )
> );
> $popularActivities = $this->Activity->find('all', array(
>   'conditions' => '1=1 GROUP BY Activity.id HAVING num_users > 0',
>   'order' => 'num_users DESC',
>   'limit' => 10,
>   'recursive' => 0
> ));
>
> Will find the 10 most popular activites, most popular first.
> Activities with no users are not returned.
>
> Also, look into counterCache - it will make this much easier for you.
>
> On May 20, 2:26 pm, Dan Soendergaard <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> > My app contains a User model and an Activity model. A User belongsTo
> > an Activity. The foreign key is activity_id.
> > Now, I want to make a list of popular activities where popularity is
> > measured by how many users are signed up for it. I'm not sure how to
> > do this. Can I use $this->Activity->find()? If yes, how do I tell it
> > that I want the count of users for each activity?
>
> > Thanks in advance :)
>
> > Sincerely,
> > Dan
--~--~---------~--~----~------------~-------~--~----~
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]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to