[英]Doctrine 2 in Symfony 2 - Filtering a QueryBuilder by an association
[英]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.