ggg*_*ggg 4 mysql symfony doctrine-orm knppaginator
我试图获得非空的集合,即至少有一个对象.集合实体与Object实体具有OneToMany关系.我正在使用KNP paginator来分页结果.这是我的功能:
public function fetchAction(Request $request){
$em = $this->getDoctrine()->getManager();
$page = $request->get('page', 1);
$limit = 10;
$collections = $em->createQueryBuilder()
->select('c')
->add('from', 'CollectionBundle:Collection c LEFT JOIN c.object o')
->having('COUNT(o.id)>0')
->orderBy('c.date', 'DESC')
->getQuery();
$collections = $this->get("knp_paginator")->paginate($collections, $page, $limit);
return $this->render('CollectionBundle:Collection:fetch.html.twig', [
'collections' => $collections
]);
}
Run Code Online (Sandbox Code Playgroud)
错误
我一直听到以下错误
Cannot count query that uses a HAVING clause. Use the output walkers for pagination
Run Code Online (Sandbox Code Playgroud)
没有'Having'子句一切正常,但我必须得到非空集合.
ggg*_*ggg 10
wrap-queries解决了这个问题
$collections = $this->get("knp_paginator")->paginate($collections, $page, $limit,array('wrap-queries'=>true));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2272 次 |
| 最近记录: |