【发布时间】:2015-07-09 23:27:09
【问题描述】:
我在 DQL 上有以下请求,使用 Doctrine 2 Query Builder,效果很好:
$qb->select('post')
->from('Posts\Entity\Post','post')
->join('post.author','author')
->where('author INSTANCE OF :utype')
->setParameter('utype',$userType);
但是,考虑到这个例子反映了大型查询的一部分,我想去掉这个join。我试过这个:
$qb->select('post')
->from('Posts\Entity\Post','post')
->where('post.author INSTANCE OF :utype')
->setParameter('utype',$userType);
但它不起作用。
如何避免使用join?或者也许还有其他方法可以优化此类查询?
谢谢
【问题讨论】:
-
会发生什么错误?
-
预期的 Doctrine\ORM\Query\Lexer::T_INSTANCE,得到 '.'靠近 post.author
-
posts 和 author 是 2 个不同的表。帖子中的加入字段将只是一个 ID。所以你必须加入。
-
也许有一些方法可以访问鉴别器列?然而,它也涉及到 join..
-
无论如何,我发现了性能问题的原因。这不是关于连接的,它是由另一部分查询中的连接语句中的 OR 条件引起的:
$qb->join($userType,'u','WITH','post.destination_member_id=u.id OR post.author_id=u.id');
标签: doctrine-orm dql instanceof