我正在尝试对使用 DQL 的查询进行分页(因为我将使用一些像 sum 之类的组函数)并且有一个外连接,这里是一个简化的代码:
//in controller
use
Pagerfanta\Pagerfanta,
Pagerfanta\Adapter\DoctrineORMAdapter as PagerAdapter;
//in list action
$query=$em->createQuery(
'select m,sum(d.amount) from
ABundle:Master m
left join ABundle:Detail d with d.master=m
group by m.date'
);
$query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, true);
$paginator=new Pagerfanta(new PagerAdapter($query));
$paginator->setMaxPerPage($this->getPerPage());
$paginator->setCurrentPage($this->getPage(),false,true);
return $paginator;
问题是我收到以下错误:
An exception has been thrown during the rendering of a template ("Cannot count query which selects two FROM components, cannot make distinction")
我一直在尝试设置一个名为的提示HINT_CUSTOM_OUTPUT_WALKER
,以便 pagerfanta 将我的查询用作视图并运行自己的计数,但我无法解决这个问题。
谁能给我一些关于如何正确使用它的指导?