"IS NOT NULL" expression with Symfony query builder
I searched for a easy way to get values that contain a not null in the where clause. That's what I came up with:
$repo = $this->getDoctrine()->getRepository('LiplexBundle:User');
$query = $repo
->createQueryBuilder('u')
->where('u.lastOnline > :lastOnline')
->andWhere('u.posts IS NOT NULL')
->setParameter('lastOnline', new \DateTime('2 days ago'))
->getQuery();
There is also a isNotNull()
expression, but the only thing it does is returning a concatenated string with IS NOT NULL
:
/**
* Creates an IS NOT NULL expression with the given arguments.
*
* @param string $x Field in string format to be restricted by IS NOT NULL.
*
* @return string
*/
public function isNotNull($x)
{
return $x . ' IS NOT NULL';
}
So there is no good reason for using anything other then just plain DQL here.