Product
与 具有 oneToMany 关系Deliverable
。DigitalDeliverable
使用 STI,我定义了几种类型的可交付成果,例如MerchDeliverable
哪个子类Deliverable
。
DigitalDeliverable
具有 oneToMany 自引用关联;aDigitalDeliverable
可能有一个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
移至其 parent Deliverable
,则查询会执行,但这会破坏使用表继承的意义。例如, aMerchDeliverable
不应该具有自引用属性。
如何在 DigitalDeliverable 上急切地加载自引用关联?
以下要点包含实体定义和查询:https ://gist.github.com/peterhorne/5831829
(我省略了查询中与问题无关的实体和子句的属性)