我使用 knppaginator 来获取分页结果。当我在查询中使用 LEFT JOIN 语句时,出现以下错误:
Cannot count query which selects two FROM components, cannot make distinction
我的控制器中的代码如下所示:
public function paginationAction()
{
$em = $this->get('doctrine.orm.entity_manager');
$dql = "SELECT p.name, c.name
FROM MyBundle:Products p
LEFT JOIN MyBundle:Categories c
WITH c.id = p.categoryId";
$query = $em->createQuery($dql);
$request = $this->getRequest();
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$query,
$request->query->getInt('page', 1),
10
);
$viewData['pagination'] = $pagination;
return $this->render('MyBundle:results.html.twig', $viewData);
}
如何使 LEFT JOIN 语句起作用?当我省略 LEFT JOIN 时,一切正常。