问题
I have this:
->select('COUNT(x)')->setMaxResults(null)->setFirstResult(0)->getQuery()->getSingleScalarResult();
this works as long as I dont have join. If I have left join, it will also count the duplicated left-columns. How to prevent that?
回答1:
You can do that by grouping:
$qb->select('COUNT(x)')
->leftJoin('x.another_table', 'a')
->groupBy('x.id')
->setMaxResults(null)
->setFirstResult(0)
->getQuery()
->getSingleScalarResult();
来源:https://stackoverflow.com/questions/36296138/doctrine-2-count-when-left-join