![]() |
|
Snippets |
|
$query = new Doctrine_Query(); $query->select('c.*, COUNT(u.id) num_users'); // soon it may be possible to do COUNT(u.id) as num_users like in sql $query->from('Church c'); $query->leftjoin('c.User u'); $query->orderby('c.name asc'); $query->groupby('c.id'); $churches = $query->execute(); foreach($churches AS $church) { echo $church->name.' - '.$church->Users[0]->num_users.'<br/>'; }
That last part is tricky, no real way to know that from any of the documentation that num_users is in $church->users[0]->num_users.
Comments on this snippet
nice snippet. just a note that in the case of a computed column WITHOUT a join, the syntax is a bit different. to wit: