0

请帮助我得到这个错误

无法计算选择两个 FROM 组件的查询,当我尝试中断查询以添加条件语句时无法区分

我已经阅读了这个 KnpPaginatorBundle/Resources/doc/manual_counting.md 并且我到达了这个

    public function findCategoryProduct($category,$minPrice=null,$maxPrice=null,$gender=null)
              {
                  $countgb = $this->createQueryBuilder('1')
              ->select('count(p)')
                  ->from('AppBundle:Product','p')
                 ->join('p.group', 'g')
                ->join('g.category', 'c')
               ->where('c = :category')
               ->andWhere('p.visible >= :true')
               ->setParameter('category', $category)
              ->setParameter('true', 1);
               $count = $countgb->getQuery()->getSingleScalarResult();
              $query = $this->createQueryBuilder('1')
            ->select('p')
            ->from('AppBundle:Product','p')
            ->join('p.group', 'g')
            ->join('g.category', 'c')
            ->where('c = :category')
            ->andWhere('p.visible >= :true')
            ->setParameter('category', $category)
            ->setParameter('true', 1);
        $query ->getQuery()
            ->setHint('knp_paginator.count', $count);
        return $query;
    }

$paginator  = $this->get('knp_paginator');
        $pagination = $paginator->paginate($query,$request->query->getInt('page', 1),10,array('distinct' => false));

我仍然得到错误

4

1 回答 1

1

嗨,我建议您使用子查询,例如: $query = $em->createQuery('SELECT u.id FROM CmsUser u WHERE EXISTS (SELECT p.phonenumber FROM CmsPhonenumber p WHERE p.user = u.id)'); $ids = $query->getResult();

或使用 expr: 这里$query->andWhere($query->expr()->notIn('c.id', $subquery->getDQL())); 有一些文档

于 2016-06-01T09:09:20.253 回答