Bartosz Rychlicki Bartosz Rychlicki - 1 year ago 163
PHP Question

pass array of conditions to doctrine expr()->orx() method

I need to construct DQL with a

like this

[QUERY]... AND WHERE e.type = x OR e.type = Y OR e.type = N [...]

I have types in array How can I pass this array to my query builder?


List of types will be dynamic, calling
on each foreach types loop will make only more AND WHERE's no more ORs.
Can I store multiply
expressions and then add it to
? Any idea how to solve this, probably, common problem?

Answer Source

I knew that tommarow gonna be a better day. The solution is simple. Your can make array of OR expressions like so

$ors[] = $qb->expr()->orx('e.type = '.$qb->expr()->literal($value));

And then just add it to andWhere()/Where() method of the query builder via join method like so:

$qb->andWhere(join(' OR ', $ors));