DEzra
DEzra

Reputation: 3038

How do I specify a variable number of OR values in a Doctrine SQL Where

How do I programatically create a Doctrine ORM call for the following SQL when I have a different number of values in the 'OR' clause on each run?

   SELECT * FROM table1
   WHERE table1.group = 1 OR 2 OR 3

Specifically, I may only want to get table1.group values of 1 OR 2 next time

Upvotes: 0

Views: 51

Answers (1)

dmnptr
dmnptr

Reputation: 4304

Your values can be in array. Sample repository method:

public function findAllInGroupList(Array $groupList)
{
    $em = $this->getEntityManager();
    $queryText  = "SELECT a FROM AcmeBundle:Acme a ";
    $queryText .= "WHERE a.group IN (:groupList)";

    $query = $em->createQuery($queryText);
    $query->setParameter('groupList', $groups);

    return $query->getResult();
}

Upvotes: 1

Related Questions