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

Doctrine 2. query builder. association INSTANCE OF type

我对 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?或者也许还有其他方法可以优化此类查询?

谢谢

我知道这是一个老问题,但仍然没有答案。
实例名称不能通过参数设置为字符串。

可以这样写:

$qb->select('post')
    ->from('Posts\Entity\Post','post')        
    ->where('post.author INSTANCE OF '.UserType::class);

或者像这样

$qb->select('post')
    ->from('Posts\Entity\Post','post')        
    ->where('post.author INSTANCE OF :utype')
    ->setParameter('utype', $entityManager->getClassMetadata(UserType::class));

@见:https://github.com/doctrine/orm/issues/6483