Product
与Deliverable
具有oneToMany关系。使用STI我已经定义了几种类型的可交付项,例如DigitalDeliverable
和MerchDeliverable
,它们是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
(我在查询中省略了与问题无关的实体和子句的属性)