I use Doctrine in my PHP application (but not using Symfony). I try to make a dynamic query with only one addWhere/orWhere.
Here is my code:
$alias = 'a';
$key = 'id';
$qb = $repo->createQueryBuilder($alias);
$qb->select($alias);
$qb->andWhere($alias . ' = ' . $key);
// Key is "id" and value is a dynamic array "[1, 2, 3, 6...]"
$qb->setParameter($key, $value);
If value is only "1" I got this DQL :
SELECT a FROM contact a WHERE a = :id
And it works. But with value as an array, I want to do this query without multiple "andOr" because my array is dynamic. Is there a method to automatically add (addWhere or orWhere) to get that automatically using my array:
SELECT a FROM contact a WHERE a = :id OR a:= id OR a:= id
I know I can do a for loop myself but I want to know if there is already an existing method in doctrine.