[英]Doctrine2 Join count on same table returning empty array
$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');
Let's assume there are two messages with employeeId = 1 and responseTo = 0. One of those messages also has two responses (therefore two other records with responseTo = messageId). 假设有两条消息,employeeId = 1,responseTo =0。其中一条消息也有两个响应(因此,另两个记录的responseTo = messageId)。 The other has none.
另一个没有。 The result I would expect from this query is two arrays with the entity object as index 0, and the count as index numResponses (value of 2 for the first row, 0 for the second).
我从该查询中期望的结果是两个数组,其中实体对象为索引0,计数为索引numResponses(第一行的值为2,第二行的值为0)。 What I'm getting back is an empty array on $messageQuery->getQuery()->getResult();
我回来的是$ messageQuery-> getQuery()-> getResult();上的一个空数组;
Does anyone have any ideas as to why this may be happening? 有谁知道为什么会发生这种情况吗? Is there something obvious I'm missing here?
有什么明显的我想念的地方吗?
实际上,我似乎已经通过切换到leftJoin修复了它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.