Php Symfony原则查询生成器OneToMany筛选

Php Symfony原则查询生成器OneToMany筛选,php,symfony,doctrine-orm,repository,Php,Symfony,Doctrine Orm,Repository,我的存储库中有以下代码 // ProductBundle/Repository/ProductRepository.php $qb->where($qb->expr()->eq('afp.id', 15)); $qb->andWhere($qb->expr()->eq('afp.id', 14)); return $qb ->select('a', 'afp') ->leftJoin('a.pro

我的存储库中有以下代码

// ProductBundle/Repository/ProductRepository.php

$qb->where($qb->expr()->eq('afp.id', 15));
$qb->andWhere($qb->expr()->eq('afp.id', 14));

return $qb
            ->select('a', 'afp')
            ->leftJoin('a.productFields', 'afp')
            ->getQuery()
            ->getResult();

但是我总是得到空返回,但我希望得到同时具有两个productFields(so或where不好)的产品。

您希望使用
成员,而不是比较
id
。否则,您将查找具有两个不同
id
值的记录,这当然是不可能的

这将满足您的要求:

$qb->where($qb->expr()->isMemberOf(15, 'a.productFields'));
$qb->andWhere($qb->expr()->isMemberOf(14, 'a.productFields'));

它在第一次尝试时不起作用:
尝试调用类“Doctrine\ORM\Query\Expr”中名为“isMemberOf”的未定义方法。
我用
$qb->where(“?a.productFields的1个成员”)$qb->andWhere(“?a.productFields的2个成员”)$qb->setParameters(['1'=>14,'2'=>15]),但我是stuckOk,这东西很好用。非常感谢你给我一个主意!现在,下一个问题是:除了
id
之外,是否可以对其他字段使用
MEMBER OF
。您可以传递整个实体而不是id,但这或多或少是相同的。如果这不适合你,请考虑添加另一个问题,并更详细地解释你的情况。