Re: Fighting cakephp : can't add user count to group index

2009-01-13 Thread Arthur Pemberton
On Tue, Jan 13, 2009 at 12:59 PM, Webweave wrote: > Or even easier (although less cake-like, probably more efficient at > the DB level): > > 'fields' => array('Group.*', '(select count(1) from users User where > User.group_id = Group.id) as users_count') Genius. I should have thought of that. I

Re: Fighting cakephp : can't add user count to group index

2009-01-13 Thread Webweave
Just add the field and groupings to the find (http://book.cakephp.org/ view/73/Retrieving-Your-Data) find('all', array('fields' => array('Group.*', '(COUNT(*)) as group_count', 'User.username') 'group' => array('Group.id', 'Group.name', 'Group.created', 'Group.modified', 'User.u

Fighting cakephp : can't add user count to group index

2009-01-12 Thread Arthur Pemberton
I was trying to do what would be a fairly simple thing in plain SQL. The bake script generated a nice groups_controller for me which paginated the groups listing. Fairly simple. All I wanted to do was add a user count to the index. The required SQL would be: SELECT `Group`.`id` , `Group`.`name`