Let A, B, C be associated entities. I'm aiming for A->getBs()
to return a collection of B
ordered by two properties: B.createdAt
and B.C.displayOrder
.
First works fine, second does not: I've tried "c.displayOrder" = "asc"
, but this has been unsuccessful (Unrecognized field: c.displayOrder
).
Is there any way to order by a property from another related entity?
The other option I could imagine is overriding the function getBs()
, but I wouldn't know how to create a custom DQL query in there to accommodate for my special need. I've read that using the EntityManager inside an Entity is bad practice.
A
/**
* @ORM\OneToMany(targetEntity="B", mappedBy="a")
* @ORM\OrderBy({"createdAt" = "asc", "c.displayOrder" = "asc"})
*/
-id
-getBs()
B
/**
* @ORM\ManyToOne(targetEntity="A")
* @ORM\JoinColumn(referencedColumnName="id")
*/
/**
* @ORM\ManyToOne(targetEntity="C")
* @ORM\JoinColumn(referencedColumnName="id")
*/
-id
-createdAt
C
-id
-description
-displayOrder
Using doctrine/orm v2.4.5, symfony-standard-edition 2.3.20