小编Vik*_*tor的帖子

原则 2. 查询生成器。关联实例类型

我使用 Doctrine 2 Query Builder 对 DQL 有以下请求,效果很好:

$qb->select('post')
    ->from('Posts\Entity\Post','post')
    ->join('post.author','author')
    ->where('author INSTANCE OF :utype')
    ->setParameter('utype',$userType);
Run Code Online (Sandbox Code Playgroud)

但是,考虑到这个例子反映了大型查询的一部分,我想摆脱这个join。我试过这个:

$qb->select('post')
    ->from('Posts\Entity\Post','post')        
    ->where('post.author INSTANCE OF :utype')
    ->setParameter('utype',$userType);
Run Code Online (Sandbox Code Playgroud)

但它不起作用。

我怎样才能避免使用join?或者也许还有其他方法来优化此类查询?

谢谢

instanceof dql doctrine-orm

2
推荐指数
1
解决办法
3773
查看次数

标签 统计

doctrine-orm ×1

dql ×1

instanceof ×1