title: Combine IS NULL and :value in Doctrine 2 DQL
body: <p>Since other (old) questions didn't get proper answers, I'll try it again:</p>
  
  <p>I regularly come across a scenario, where I want to query an entity with a specific value:</p>
  
  <pre><code>$query = $em-&gt;createQuery('SELECT e FROM Entity e WHERE e.parent = :parent');
  $query-&gt;setParameter('parent', $parent);
  </code></pre>
  
  <p>Often, this value can be NULL, but <code>WHERE e.parent = NULL</code> yields no results, forcing me to hack around like this:</p>
  
  <pre><code>if ($parent === null) {
      $query = $em-&gt;createQuery('SELECT e FROM Entity e WHERE e.parent IS NULL');
  }
  else {
      $query = $em-&gt;createQuery('SELECT e FROM Entity e WHERE e.parent = :parent');
      $query-&gt;setParameter('parent', $parent);      
  }
  </code></pre>
  
  <p>While I understand the rationale behind NULL != NULL in SQL / DQL, the fact is, the consequence is really annoying in this case.</p>
  
  <p>Also, an example given in an older question doesn't work in DQL, for NULL != NULL.</p>
  
  <pre><code>-&gt;setParameter('parent', (is_null($parent) ? "NULL" : $parent));
  </code></pre>
  
  <p>I also tried this way, what someone kindly offered, but this will give a NonUniqueResult exception, because when parent is 1 for example, it'll give a double result.</p>
  
  <pre><code>SELECT e 
  FROM Entity e 
  WHERE (e.parent = :parent OR e.parent IS NULL)
  </code></pre>
  
  <p><strong>Is there a cleaner way to perform this query, when the parameter can be null?</strong></p>