Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 Doctrine Expr 'IS NOT NULL'

I'm using the FormType for an Entity of mine, and setting up an entity field. I need two Where clauses in an And, and from what I've read on the Query Builder page, this is at least how I should go about it:

'query_builder' => function ($er){     $qb = $er->createQueryBuilder('p');     $qb         ->where($qb->expr()->andx(             $qb->expr()->in('p', '?1'),             $qb->expr()->not(                 $qb->expr()->eq('p.location', 'NULL')             )         ))         ->setParameter(1, $this->totalScope)     ;     return $qb; }, 

However, the not(eq('col', 'NULL')) doesn't achieve the desired result, and in fact, errors with:

Error: Expected Literal, got 'NULL'

like image 236
Rixius Avatar asked Apr 02 '13 20:04

Rixius


1 Answers

You can use isNotNull:

'query_builder' => function ($er){     $qb = $er->createQueryBuilder('p');     $qb         ->where($qb->expr()->andx(             $qb->expr()->in('p', '?1'),             $qb->expr()->isNotNull('p.location')         ))         ->setParameter(1, $this->totalScope);      return $qb; }, 
like image 109
Ocramius Avatar answered Sep 28 '22 15:09

Ocramius