Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use sort() on multiple fields in Doctrine 2 ODM?

I am doing a query on a result document in my doctrine mongodb *odm*. There are two indexed fields in the document which I would like to use in sort. I have written something like:

$results = $this->createQueryBuilder('Document\Score')
            ->sort('finalScore', 'desc')
            ->sort('date', 'desc')
            ->getQuery()
            ->execute();

Here the second sort() function overrides the first one and the designated result is never found.

Thanks in advance for the nice help.

like image 949
Himel Nag Rana Avatar asked Jul 08 '12 11:07

Himel Nag Rana


1 Answers

Try this

$qb = $this->createQueryBuilder('Document\Score');
$qb->sort(array(
    'finalScore' => 'desc',
    'date'       => 'desc',
));
$results = $qb->getQuery()->execute();
like image 197
AdrienBrault Avatar answered Sep 21 '22 01:09

AdrienBrault