I have the following code
public function queryAssociationsSorted($id){
$qb = $this->createQueryBuilder('a')
->leftJoin('a.category', 'c')
->where('a.job = :id')
->setParameter('id', $id)
//->addOrderBy('c.rank', 'DESC')
//->addOrderBy('a.updated', 'DESC')
->add('orderBy','c.rank DESC THEN a.updated DESC')
;
return $query = $qb->getQuery();
}
and this or the commented out options both only sort by a.updated. I have looked at other posts on this subject and can't find a solution. Can anyone suggest where I am going wrong?
If I understand correctly, and this is the result yu want:
id - rank - updated
xx - 4 - 2014-01-01
xx - 3 - 2014-01-02
xx - 3 - 2014-01-01
This actually works:
$qb = $this->createQueryBuilder('a')
->leftJoin('a.category', 'c')
->where('a.job = :id')
->setParameter('id', $id)
->addOrderBy('c.rank', 'DESC')
->addOrderBy('a.updated', 'DESC')
;
return $query = $qb->getQuery();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With