MeuMySQL Blog is now at

Tuesday, October 9, 2012

[en] Doctrine, specifying Null values

Hi guys! I'd like to share a doubt I had other day here about using Doctrine queries. I was trying to write a query to return only records with a certain null value column, to do so all you need to do is something like below:
$query = Doctrine_Query::create()
  ->from('entityName t1')
  ->where('t1.columnName is NULL');

$resultSet = $query->execute(array(), Doctrine::HYDRATE_ARRAY);

Easy and simple. Works the same way for both DQLs and queries in Doctrine.

$dql = $entityManager->createQueryBuilder()
           ->from('ns:Entity', 't')
           ->where('t.columnName is NULL ');

$arrayOfData = $dql->getQuery()->execute();


No comments:

Post a Comment