Symfony2 pagerfanta DQL with leftjoin



我正在尝试对使用 DQL 的查询进行分页(因为我将使用一些组函数,如 sum(并具有外部连接,这里是简化的代码:

//in controller
use
PagerfantaPagerfanta,
PagerfantaAdapterDoctrineORMAdapter 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 将我的查询用作视图并运行自己的计数,但我无法解决这个问题。

任何人都可以给我一些关于如何正确使用它的指导吗?

改用 pagerfanta 数组适配器,它使用左连接运行查询,然后使用结果对数组进行分页。

最新更新