Symfony 分组依据的doctrine2分页器错误
我使用此DQL获取一些数据,但在使用doctrine2 paginator时出错:Symfony 分组依据的doctrine2分页器错误,symfony,doctrine-orm,dql,Symfony,Doctrine Orm,Dql,我使用此DQL获取一些数据,但在使用doctrine2 paginator时出错: SELECT f FROM DankeForumBundle:Forumusermessage f WHERE f.recipientdelete=0 GROUP BY f.forwarder HAVING f.recipient=:recipient 这是因为条令执行此查询以计数页面: SELECT count(DISTINCT f.id) FROM Forumusermessage AS f
SELECT f FROM DankeForumBundle:Forumusermessage f
WHERE f.recipientdelete=0
GROUP BY f.forwarder
HAVING f.recipient=:recipient
这是因为条令执行此查询以计数页面:
SELECT count(DISTINCT f.id) FROM Forumusermessage AS f
WHERE f.recipientdelete=0
GROUP BY f.forwarder_id
HAVING f.recipient_id=:recipient
有没有办法不使用本机SQL查询对此进行分页
编辑:
这是一个PHP代码示例:
$query = $this->getEntityManager()->createQuery('SELECT f FROM DankeForumBundle:Forumusermessage f
WHERE f.recipientdelete=0
GROUP BY f.forwarder
HAVING f.recipient=:recipient');
$query->setParameter('recipient', $user);
$query->setFirstResult(0);
$query->setMaxResults(10);
$paginator = new \Doctrine\ORM\Tools\Pagination\Paginator($query);
echo count($paginator); // wrong page count
我发现了一种使用子查询的解决方法:
SELECT f FROM DankeForumBundle:Forumusermessage f
WHERE
f.recipientdelete=0 AND
f.recipient=:recipient
AND f.id IN (
SELECT fn FROM DankeForumBundle:Forumusermessage fn
GROUP BY fn.forwarder
)