WHERE a = 1 AND (b = 1 Or b = 2) AND (c = 1 OR c = 2)
Come posso fare questo in Doctrine?
$q->where("a = 1"); $q->andWhere("b = 1") $q->orWhere("b = 2") $q->andWhere("c = 1") $q->orWhere("d = 2")
questo non è corretto … dovrebbe essere:
$q->where("a = 1"); $q->andWhere("b = 1") $q->orWhere("b = 2") $q->andWhere("c = 1") $q->orWhere("d = 2")
ma come posso farcela? In Propel è la function getNewCriterion e in Doctrine …?
$q->where("a = 1") ->andWhere("b = 1 OR b = 2") ->andWhere("c = 2 OR c = 2") ;
Ecco un esempio per coloro che hanno condizioni più complicate e utilizzano Doctrine 2. * con QueryBuilder
:
$qb->where('o.foo = 1') ->andWhere($qb->expr()->orX( $qb->expr()->eq('o.bar', 1), $qb->expr()->eq('o.bar', 2) )) ;
Quelle sono espressioni menzionate nella risposta di Czechnology.
Perché non solo
$q->where("a = 1"); $q->andWhere("b = 1 OR b = 2"); $q->andWhere("c = 1 OR d = 2");
EDIT : puoi anche usare la class Expr (Doctrine2).