Search code examples
symfonydoctrine-ormdql

Doctrine2 empty parameter on queryBuilder


I am trying to check whether an user email is set or not. I am able to get the ones that are set to NULL but I am missing on the ones that have an empty string as the value. Here is my attempt:

$user = $this->createQueryBuilder('u')
        ->where('(u.email IS NULL OR u.email = :empty)')
        ->setParameter('empty', "''")
        ->getQuery()->getResult()
;

I have no problem getting the NULL emails but I fail to get the empty string emails. Is there any way to accomplish this or is it not supported in DQL?


Solution

  • How about this (EDIT #2):

    $user = $this->createQueryBuilder('u')
            ->where('u.email = NULL')
            ->orWhere('u.email = \'\'')
            ->getQuery()->getResult()
    ;
    

    Does that work?