如何在 Doctrine 中使用 andWhere 和 or Where?

2022-01-16 00:00:00 sql php doctrine
WHERE a = 1 AND (b = 1 Or b = 2) AND (c = 1 OR c = 2)

我怎样才能在 Doctrine 中做到这一点?

How can i make this in Doctrine?

$q->where("a = 1");
$q->andWhere("b = 1")
$q->orWhere("b = 2")
$q->andWhere("c = 1")
$q->orWhere("d = 2")

这不正确...应该是:

this isnt correctly... Should be:

$q->where("a = 1");
$q->andWhere("b = 1")
   $q->orWhere("b = 2")
$q->andWhere("c = 1")
   $q->orWhere("d = 2")

但是我怎样才能做到呢?在 Propel 中是函数 getNewCriterion,而在 Doctrine 中...?

but how can i make it? In Propel is function getNewCriterion, and in Doctrine...?

推荐答案

$q->where("a = 1")
  ->andWhere("b = 1 OR b = 2")
  ->andWhere("c = 2 OR c = 2")
  ;

相关文章