我有3个实体:
My\Bundle\Entity\Investment:
type: entity
fields:
# ...
oneToMany:
payouts:
targetEntity: My\Bundle\Entity\Payout
mappedBy: investment
orderBy: {operation.effectiveDate: 'ASC'}
My\Bundle\Entity\Payout:
type: entity
fields:
# ...
manyToOne:
investment:
targetEntity: My\Bundle\Entity\Investment
inversedBy: payouts
operation:
targetEntity: My\Bundle\Entity\Operation
inversedBy: payouts
My\Bundle\Entity\Operation:
type: entity
fields:
effectiveDate:
type: datetime
# ...
oneToMany:
payouts:
targetEntity: My\Bundle\Entity\Payout
mappedBy: operation
正如您所看到的,investment
有多个payouts
附加到一个operation
我希望investment.payouts
订购payout.operation.effectiveDate
。
我尝试使用orderBy: {operation.effectiveDate: 'ASC'}
,但它不起作用。
所以问题是:
如何按investment.payouts
订购payout.operation.effectiveDate
?
答案 0 :(得分:3)
为什么不使用存储库功能?
public function getPayouts() {
$em = $this->getEntityManager();
$sql = 'SELECT i, p, o '
. 'FROM AppBundle:Investment i '
. 'JOIN i.payouts p '
. 'JOIN p.operation o '
. 'ORDER BY o.effectiveDate ';
$query = $em->createQuery($sql);
return $query->getResult();
}