草庐IT

mysql - Symfony2 Doctrine 错误 : Cannot count query that uses a HAVING clause. 使用输出 walkers 进行分页

coder 2023-10-08 原文

我正在尝试获取非空的集合,即至少有 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' 子句一切正常,但我必须获得非空集合。

最佳答案

wrap-queries 解决了这个问题

 $collections = $this->get("knp_paginator")->paginate($collections, $page, $limit,array('wrap-queries'=>true));

关于mysql - Symfony2 Doctrine 错误 : Cannot count query that uses a HAVING clause. 使用输出 walkers 进行分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34046294/

有关mysql - Symfony2 Doctrine 错误 : Cannot count query that uses a HAVING clause. 使用输出 walkers 进行分页的更多相关文章

随机推荐