我必须在添加子句之后立即将OR表达式动态地添加到所返回的查询构建器中。我找不到任何合适的方式来做到这一点,我才刚刚开始学习Doctrine。getListQueryBuilder``where
OR
getListQueryBuilder``where
我如何“链接”给定数量的orX并将其添加到我的构建器中?
orX
public function getListQueryBuilder($ownerId) { $qb = $this->createQueryBuilder('t'); return $qb ->where($qb->expr()->eq('t.user', ':user')) ->setParameter('user', $ownerId); } $builder = getListQueryBuilder(4); // $ORs is a dynamically builded array, here is just an example $ORs = array(); $ORs[] = $builder->expr()->like("t.name", 'my name'); $ORs[] = $builder->expr()->like("t.description", 'desc'); // Adding ORs to the builder $builder->andWhere($builder->expr()->orX(/* here */));
您可以检查此解决方案:
$orX = $builder->expr()->orX(); foreach($ORs as $or) { $orX->add($or); } $builder->andWhere($orX);