使用Doctrine加入父类时,在STI子类上加载关联

时间:2013-06-21 16:04:14

标签: php doctrine-orm sti

ProductDeliverable具有oneToMany关系。使用STI我已经定义了几种类型的可交付项,例如DigitalDeliverableMerchDeliverable,它们是Deliverable的子类。

DigitalDeliverable具有oneToMany自引用关联; DigitalDeliverable可能有parent或许多children

我需要编写一个DQL查询来加载一些产品并急切地加载所有引用的可交付成果。这就是我想要做的事情:

$this->createQueryBuilder('p')
    ->select('p', 'd', 'c')
    ->leftJoin('p.deliverables', 'd')
    ->leftJoin('d.children', 'c');
    ->getQuery()
    ->getResult();

导致此错误: [Semantical Error] line 0, col 136 near 'c LEFT JOIN d.pricings': Error: Class Deliverable has no association named children

如果我将自引用关联从DigitalDeliverable移动到其父Deliverable,那么查询将执行,但这会破坏使用表继承的点。例如,MerchDeliverable不应具有自引用属性。

如何在DigitalDeliverable上急切加载自引用关联?

以下要点包含实体定义和查询:https://gist.github.com/peterhorne/5831829

(我在查询中省略了与问题无关的实体和子句的属性)

0 个答案:

没有答案