afn afn - 2 years ago 352
SQL Question

Doctrine - Not equal to some value

I want to detect id that are not equal to 1,2,3 or NULL . here is my query:

$qb = $this->_em->createQueryBuilder()
->from('.....\Entities\Cities', 'u')
->where("u.cityId is null OR u.cityId NOT IN (:parentType) ")
->setParameter('parentType' , "2,3,10");
$qb = $qb->getQuery();
return $qb->getResult();

Although it shows me id which are NULL or not equal to 2 and another values. It's not restrict 3,10. Any suggestion?

Answer Source

You need to pass an array. Try this:

->setParameter('parentType' , array(2,3,10) );

Instead of:

->setParameter('parentType' , "2,3,10");

Hope this help

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download