John Smith
John Smith

Reputation: 6197

Doctrine 2, how to order the joined records:

I want to get all images of a person and order by sequentally. I have this:

person entity:

return $this->createQueryBuilder('p')
    ->leftJoin('p.personImages','c')
    ->orderBy('c.sequence', 'asc')
    ->getQuery() 
    ->getResult();

orderBy() has no effect, not even asc|desc. But if I misstype this field, it dies.

Upvotes: 1

Views: 384

Answers (1)

DevDonkey
DevDonkey

Reputation: 4880

youve not 'selected' anything from the right hand table. Because of this c.sequence will be null.

try this:

return $this->createQueryBuilder('p')
    ->select('p')
    ->leftJoin('p.personImages','c')
    ->addSelect('c')
    ->orderBy('c.sequence', 'asc')
    ->getQuery() 
    ->getResult();

Upvotes: 1

Related Questions