I have a $value
variable containing "Open|Close". I would like to use a doctrine query in Symfony to get all "status" with the word "Open" or "Close". For that I try to use a regex. However, I get the following error:
[Semantical Error] line 0, col 75 near 'status, :regexp)': Error:
Invalid PathExpression. Must be a StateFieldPathExpression.
Here is my code:
$qb = $this->createQueryBuilder('q')
->andWhere('REGEXP(q.status, :regexp) = true')
->setParameter('regexp', '|');
I have the DoctrineExtensionsBundle
and I have updated my app/config.yml
What about using the explode() function and SQL IN operator ?
$qb = $this->createQueryBuilder('q')
->andWhere('q.status IN (:status)')
->setParameter(':status', explode('|', $value));
It will return all records having either "Open" or "Close" in the status column.