【问题标题】:Symfony2 pagerfanta DQL with leftjoinSymfony2 pagerfanta DQL with leftjoin
【发布时间】:2013-10-10 21:27:24
【问题描述】:

我正在尝试对使用 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 将我的查询用作视图并运行它自己的计数,但我无法解决这个问题。

谁能给我一些关于如何正确使用它的指导?

【问题讨论】:

标签: symfony dql hint pagerfanta


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-11
    • 1970-01-01
    相关资源
    最近更新 更多