2013-10-10 48 views
1

我想分頁使用DQL(因爲我要使用像總和一些組功能),並具有外部連接,這裏的簡化代碼的查詢:Symfony2的pagerfanta DQL與leftjoin

//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使用我的查詢作爲視圖和運行其自己的計數,但我一直沒能解決此問題。

任何人都可以請給我一些關於如何正確使用它的指導?

+0

仍在研究:https://github.com/whiteoctober/Pagerfanta/issues/59 它似乎是一個問題與教條paginator當我離開連接 –

回答

1

改爲使用pagerfanta數組適配器,它使用左連接運行查詢,然後使用結果對數組進行分頁。