0

I want my doctrine 2 query below to have more than 1 "order by" category.

However, I noticed that doctrine 2 only supports the last last "order by query" i.e:

 ->orderBy('u.qualityOfPictures', 'DESC');

Does anyone know whether doctrine 2 supports more than 1 "order by"

If so, what is the correct way to format it.

my query

$qb  =  $this->queryBuilder()
                      ->select(array('u'))
                       ->from('BaseModel\Entity\User','u')
                       ->orderBy('u.dateOfRegistration', 'DESC')
                        ->orderBy('u.qualityOfPictures', 'DESC');

thank you

Paul Kendal
  • 559
  • 9
  • 24
  • [Order by multiple columns with Doctrine](http://stackoverflow.com/questions/11575325/order-by-multiple-columns-with-doctrine) – slaur4 Jan 22 '15 at 15:18

1 Answers1

0

Query builder allows you to add order by using the construction addOrderBy:

          $qb  = $this->queryBuilder()
                      ->select(array('u'))
                      ->from('BaseModel\Entity\User','u')
                      ->orderBy('u.dateOfRegistration', 'DESC')
                      ->addOrderBy('u.qualityOfPictures', 'DESC');

The order in the generated SQL is the natural order: first goes orderBy and then the addOrderBy in the order you defined them in the query.

acontell
  • 6,792
  • 1
  • 19
  • 32