DQL (Doctrine Query Language) - SELECT queries - Aggregate values.php 394 Bytes
Newer Older
hansbrix's avatar
hansbrix committed
1
Aggregate value SELECT syntax:
2

hansbrix's avatar
hansbrix committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16
<code type="php">
// SELECT u.*, COUNT(p.id) num_posts FROM User u, u.Posts p WHERE u.id = 1 GROUP BY u.id

$query = new Doctrine_Query();

$query->select('u.*, COUNT(p.id) num_posts')
      ->from('User u, u.Posts p')
      ->where('u.id = ?', 1)
      ->groupby('u.id');

$users = $query->execute();

echo $users->Posts[0]->num_posts . ' posts found';
</code>