我正在尝试获取非空的集合,即至少有 1 个对象。Collection 实体与 Object 实体具有 OneToMany 关系。我正在使用 KNP 分页器对结果进行分页。这是我的功能:
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
]);
}
错误
我不断收到以下错误
Cannot count query that uses a HAVING clause. Use the output walkers for pagination
没有 'Having' 子句一切正常,但我必须得到非空集合。