Doctrine 2, count when left join

一个人想着一个人 提交于 2021-02-11 12:24:28

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!