title: Retrieve children from self-referencing entity with certain condition in Doctrine 2
body: <p>I have an entity <code>Post</code> and it has, among others, the properties <code>parent</code>, <code>children</code> and <code>published</code>. The property <code>parent</code> is a manyToOne relationship and <code>children</code> a oneToMany relationship to itself. The <code>published</code> property is a boolean.</p>
  
  <p>I want to get a <code>Post</code> with a certain ID, with the children that are published, so have <code>published</code> set to true.</p>
  
  <p>I want to achieve this with the QueryBuilder or in DQL. I tried the following, but it still returned the not-published children as well.</p>
  
  <pre><code>    $dql = $this-&gt;getEntityManager()-&gt;createQuery('
          SELECT
              p
          FROM
              SomeBundle\Entity\Post p
          LEFT JOIN
              p.children pc WITH pc.published = :published
          WHERE
              p.id = :id
      ');
  
      $dql-&gt;setParameters(array(
          'id' =&gt; $id,
          'published' =&gt; true
      ));
  </code></pre>