Symfony / Doctrine QueryBuilder Join WITH不过滤行 [英] Symfony/Doctrine QueryBuilder Join WITH not filtering out rows
本文介绍了Symfony / Doctrine QueryBuilder Join WITH不过滤行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
类SongRepository扩展EntityRepository
{
public function getAllSongsWithRatings $ section $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
$ > from('RateBundle:Song','s')
- > leftJoin('s.ratings','r','WITH','r.user =:user')
- > setParameter('user',$ user);
return $ qb-> getQuery() - > getResult();
}
}
解决方案
尝试与 addSelect
:
$ qb = $ this-> getEntityManager ) - > createQueryBuilder()
- > select('s')
- > from('RateBundle:Song','s')
- > leftJoin
- > addSelect('r')
- > setParameter('user',$ user) ;
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. 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
:
$qb = $this->getEntityManager()->createQueryBuilder()
->select('s')
->from('RateBundle:Song','s')
->leftJoin('s.ratings','r','WITH','r.user = :user')
->addSelect('r')
->setParameter('user', $user);
这篇关于Symfony / Doctrine QueryBuilder Join WITH不过滤行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文