我使用此 DQL 获取一些数据,但在使用教义 2 分页器时出现错误:
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