Auro
Auro

Reputation: 67

OrderBy a relation in an entity

I've got a headache :) Been trying to google this for an hour, and before that trying to solve it for an hour.

I've got an entity A with a ManyToOne relation to another entity B. I need to sort a select of A by one of B's parameters.

i.e. $qb->addOrderBy('p.dogShowClass.weight', 'ASC')

I'm lost. Help! :) I will be monitoring this closely, if you need any further details, please do write and I will get it to you ASAP

Upvotes: 0

Views: 64

Answers (1)

Nicolai Fröhlich
Nicolai Fröhlich

Reputation: 52493

$query = $repo->createQueryBuilder('p')
    ->join('p.dogShowClass', 'd')
    ->orderBy('d.weight', 'ASC')
    ->getQuery()
;

Upvotes: 1

Related Questions