相关实体字段的学说顺序

时间:2015-12-22 17:36:29

标签: symfony doctrine-orm yaml

我有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

1 个答案:

答案 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();
}