Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Doctrine orm 条令2:产品是否等于多个类别的查询_Doctrine Orm_Query Builder_Doctrine Query - Fatal编程技术网

Doctrine orm 条令2:产品是否等于多个类别的查询

Doctrine orm 条令2:产品是否等于多个类别的查询,doctrine-orm,query-builder,doctrine-query,Doctrine Orm,Query Builder,Doctrine Query,这不允许多个位置 $categories是一个数组,它由它必须匹配的类别组成,以便选择正确的产品。比如鞋子(3双)、黑色(20双)、小号(24双) 可能吗?在条令文件中,我发现: $categories= array(3,20,24); $qb = $this->em->createQueryBuilder(); $qb->select('p') ->from('\Entities\Productss', 'p')

这不允许多个位置

$categories是一个数组,它由它必须匹配的类别组成,以便选择正确的产品。比如鞋子(3双)、黑色(20双)、小号(24双)


可能吗?

在条令文件中,我发现:

$categories= array(3,20,24);    

$qb = $this->em->createQueryBuilder();
        $qb->select('p')
                ->from('\Entities\Productss', 'p')
                ->leftJoin('p.category', 'c')
                ->andWhere('p.id =?1')
                ->andWhere('p.id =?2')
                 ->andWhere('p.id =?2')
             ->setParameter(1, $categories[0])             
->setParameter(2, $categories[1])
->setParameter(3, $categories[2])

                ->getQuery();
应该可以在此函数中放置子查询。我自己从来没用过,但试一下

编辑

我知道这是一种多对多的关系。在这种情况下,您应该使用的
成员选项

就像:

// Example - $qb->expr()->in('u.id', array(1, 2, 3))
// Make sure that you do NOT use something similar to $qb->expr()->in('value', array('stringvalue')) as this will cause Doctrine to throw an Exception.
// Instead, use $qb->expr()->in('value', array('?1')) and bind your parameter to ?1 (see section above)
public function in($x, $y); // Returns Expr\Func instance

// Example - $qb->expr()->notIn('u.id', '2')
public function notIn($x, $y); // Returns Expr\Func instance
$qb->expr()->in()。也就是说,Id在1、2或3中。我需要知道它是否在1、2和3中
$qb->...
   ->andWhere("p.category MEMBER OF ?1")
   ->andWhere("p.category MEMBER OF ?2")
   ->...