[英]Symfony/Doctrine QueryBuilder Join WITH not filtering out rows
I am building an application where I have Songs and Ratings. 我正在构建一个具有歌曲和评级的应用程序。 I need to select all Songs with its associated Ratings for the current logged in user. 我需要为当前登录用户选择所有带有其关联的乐曲的歌曲。 I try to do this, but the WITH clause is not working. 我尝试这样做,但是WITH子句不起作用。 It keeps fetching all ratings for each song. 它会不断获取每首歌曲的所有评分。
class SongRepository extends EntityRepository
{
public function getAllSongsWithRatings($section, $user)
{
$qb = $this->getEntityManager()->createQueryBuilder()
->select('s')
->from('RateBundle:Song','s')
->leftJoin('s.ratings','r','WITH','r.user = :user')
->setParameter('user', $user);
return $qb->getQuery()->getResult();
}
}
Try with addSelect
: 尝试使用addSelect
:
$qb = $this->getEntityManager()->createQueryBuilder()
->select('s')
->from('RateBundle:Song','s')
->leftJoin('s.ratings','r','WITH','r.user = :user')
->addSelect('r')
->setParameter('user', $user);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.