Thursday, August 30, 2012

Need a count value for each row from another table in index view

Hello,

I'm pretty new to Cake, but I think I'm starting to get around it.. 

However, now I am struggling. I have two models, Game and User. With the HasMany Through method I'm linking Users to a game that they are gonna play. I've also managed to, using the counter cache method, count the number of users for a game, and the numbers of games for a user. 

Now to the problem. In the index view of my games I would also like to count the number of MALE users, and the number of FEMALE users for that particular game. In the view method, that's not I problem for me as I'm only dealing with one given id, and can run multiple queries. 

So, how to run a $this->Game->find('all'), but also join in a conditioned count value from another table? 

Without Cake (and MVC) I'd list all games and for each row run two more queries to check for number of male and female. 

Thank you very much for any help! 

--
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.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
 
 

No comments: