Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Symfony 返回空数组的同一表上的Doctrine2联接计数_Symfony_Join_Doctrine Orm_Inner Join_Query Builder - Fatal编程技术网

Symfony 返回空数组的同一表上的Doctrine2联接计数

Symfony 返回空数组的同一表上的Doctrine2联接计数,symfony,join,doctrine-orm,inner-join,query-builder,Symfony,Join,Doctrine Orm,Inner Join,Query Builder,假设有两条消息,employeeId=1,responseTo=0。其中一条消息也有两个响应(因此还有两条responseTo=messageId的记录)。另一个没有。我希望从这个查询中得到两个数组,其中实体对象作为索引0,计数作为索引numResponses(第一行的值为2,第二行的值为0)。我得到的是$messageQuery->getQuery()->getResult()上的一个空数组 有人知道为什么会发生这种情况吗?这里有什么明显的遗漏吗?实际上,我似乎已经通过切换到leftJoin来

假设有两条消息,employeeId=1,responseTo=0。其中一条消息也有两个响应(因此还有两条responseTo=messageId的记录)。另一个没有。我希望从这个查询中得到两个数组,其中实体对象作为索引0,计数作为索引numResponses(第一行的值为2,第二行的值为0)。我得到的是$messageQuery->getQuery()->getResult()上的一个空数组


有人知道为什么会发生这种情况吗?这里有什么明显的遗漏吗?

实际上,我似乎已经通过切换到leftJoin来修复了它

$messageQuery
            ->select('m, COUNT(pm) AS newResponses')
            //->addSelect($messageQuery->expr()->countDistinct('pm.id'))
            ->from('entities:PrivateMessage', 'm')
            ->where('m.employeeId = :employeeId AND m.responseTo = 0')
            ->innerJoin('entity:PrivateMessage', 'pm', 'WITH', 'pm.responseTo = m.id AND pm.employeeRead = 0')
            ->setParameter('employeeId', $employeeId)
            ->setFirstResult($offset)
            ->setMaxResults($max)
            ->addGroupBy('m.id')
            ->orderBy('m.id', 'DESC');