繁体   English   中英

Symfony Doctrine QueryBuilder OneToMany 过滤

[英]Symfony Doctrine QueryBuilder OneToMany filtering

我的存储库中有以下代码

// 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();

但我总是得到 null 回报,但我想获得同时具有两个 productFields 的产品(所以 orWhere 不好)。

您想使用MEMBER OF而不是比较id 否则,您正在寻找具有两个不同id值的记录,这当然是不可能的。

这将执行您想要的操作:

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

尝试这样的事情(Symfony 5):

$qb->andWhere(':c MEMBER OF a.productFields');
$qb->setParameter('c', 15);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM