This commit is contained in:
parent
78b4dc24c5
commit
b5754f10c7
1 changed files with 25 additions and 0 deletions
|
@ -28,4 +28,29 @@ FROM User u LEFT JOIN u.Email e
|
|||
|
||||
|
||||
+++ Sorting by an aggregate value
|
||||
|
||||
In the following example we fetch all users and sort those users by the number of phonenumbers they have.
|
||||
<code type='php'>
|
||||
$q = new Doctrine_Query();
|
||||
|
||||
$users = $q->select('u.*, COUNT(p.id) count')
|
||||
->from('User u')
|
||||
->innerJoin('u.Phonenumber p')
|
||||
->orderby('count');
|
||||
</code>
|
||||
|
||||
+++ Using random order
|
||||
|
||||
In the following example we use random in the ORDER BY clause in order to fetch random post.
|
||||
<code type='php'>
|
||||
$q = new Doctrine_Query();
|
||||
|
||||
$posts = $q->select('p.*, RANDOM() rand')
|
||||
->from('Post p')
|
||||
->orderby('rand')
|
||||
->limit(1)
|
||||
->execute();
|
||||
|
||||
$randomPost = $posts[0];
|
||||
</code>
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue