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
: