例如: 我有实体Post ...帖子有实体的集合评论 - 关系是oneToMany 注释可以通过参数deletedAt删除,默认为NULL 评论有另一个实体B的集合 - 关系是oneToMany
我为querybuilder做了最优化:
$qb = $this->createQueryBuilder('post');
$qb->select('post, comments, objectsOfB')
->andWhere('post.id = :id')->setParameter('id', $postId)
->leftJoin('post.comments', 'comments')
->andWhere('comments.deletedAt is NULL')
->leftJoin('comments.objectsOfB', 'objectsOfB');
如何解决?
答案 0 :(得分:1)
将deletedAt
检查移至联接:
$qb = $this->createQueryBuilder('post');
$qb->select('post, comments, objectsOfB')
->andWhere('post.id = :id')->setParameter('id', $postId)
->leftJoin('post.comments', 'comments', 'WITH', 'comments.deletedAt is NULL')
->leftJoin('comments.objectsOfB', 'objectsOfB');