Doctrine2过滤查询类表继承中的子属性

时间:2017-05-07 21:55:03

标签: inheritance doctrine-orm doctrine

当对象具有此属性时,我试图在子属性上过滤使用QueryBuilder创建的Doctrine查询。 基本上,我有一个抽象的课程Accommodation HouseTent作为Class table inheritance, as described in the documentation的孩子。 House类具有owner属性,Tent不具有$qb = $this->createQueryBuilder('a') ->select('a') ->andWhere('(a NOT INSTANCE OF "House") OR (a INSTANCE OF "House" AND a.owner = :owner)') ->setParameter("owner", $user); 属性。 这就是我创建queryBuilder的方法。

owner

这样做我收到错误消息,指出Accommodation不存在owner

  

[语义错误]第0行,第299行附近'owner =:owner)':错误:类AppBundle \ Entity \ Accommodation没有名为owner的字段或关联

有没有办法让Doctrine加入EC PARAMETERS专栏?

PS:这是Symfony3项目的一部分,但我认为这个问题并不重要。

1 个答案:

答案 0 :(得分:0)

阅读those mailing list posts,我想做的事是不可能的。所以我最终在Accommodation表中使用andWhere(a NOT INSTANCE OF "House")进行了2次查询,在House表上进行了第二次查询以获得其余的查询。

这不是真正的性能最佳,但它是我看到的唯一解决方法。

如果有人看到任何其他解决方案,可以自由完成。