Answer the question
In order to leave comments, you need to log in
How to set condition using innerJoin in createQueryBuilder?
It is necessary that if $statuses is present, innerJoin is used, and if $statuses is absent, it is not used.
$all = $this
->createQueryBuilder('u')
->select('count(u.id)')
->innerJoin('u.roles', 'r', 'WITH', 'r.id IN (' . $statuses . ')')
->getQuery()
->getSingleScalarResult();
Answer the question
In order to leave comments, you need to log in
What's the problem?
// За форматирование извиняюсь - писал всё вручную
$qb = $this->createQueryBuilder('u')->select('...');
if ($statuses) {
$qb->innerJoin()
}
$all = $qb->getQuery()->getSingleScalarResult();
This is how it works
$qb = $this->createQueryBuilder('u')->select('...');
if ($statuses) {
$qb = $qb->innerJoin()
}
$qb = $qb->getQuery();
$all = $qb->getSingleScalarResult();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question