I have two entities Message and Skill, and many to many relationship between them. I am trying to get all messages with skill=5 or without any skills.
$queryBuilder = $repository->createQueryBuilder('entity');
$queryBuilder->leftJoin('entity.skills', 'skill');
$queryBuilder->andWhere(
$criteria->expr()->orX(
$criteria->expr()->eq('skill.id', 5),
$criteria->expr()->isNull('skill.id')
)
)
But in results I have question ONLY with skill=5. How can I select questions without skill or with skill=5 is SINGLE query?
leftJoin():$queryBuilder->leftJoin('entity.skills', 'skill', 'WITH', 'skill.id = 5 OR skill.id IS NULL');(and getting rid if thewherecalls in that case)? - ccKep