title: Doctrine/Symfony query builder add select on left join
body: <p>I have a table of posts related many to one to a table of authors. Both tables are related to a third table (likes) that indicates which users have liked which posts. I'd like to select the authors and likes with the posts, but don't know how to access the joined objects after fetching results. My query builder looks as follows:</p>
  
  <pre><code>$result = $em-&gt;createQueryBuilder()
               -&gt;select('p')              
               -&gt;from('Post', 'p')
               -&gt;leftJoin('p.author', 'a')
               -&gt;leftJoin('p.likes', 'l', 'WITH', 'l.post_id = p.id AND l.user_id = 10')
               -&gt;where("p.foo = bar")
               -&gt;addSelect('a AS post_author')
               -&gt;addSelect('l AS post_liked')
               -&gt;getQuery()-&gt;getResult();
  </code></pre>
  
  <p>In the above, the author will always be valid, where the like value may be null if the requesting user (user 10 in the example) has not interacted with the post. The query works fine, but I can't access the data for aliases post_author or post_liked. The resulting data looks like this:</p>
  
  <pre><code>[
    [0] =&gt; Doctrine PostEntity,
    [1] =&gt; Doctrine PostEntity,
    ...
  ]
  </code></pre>
  
  <p>I'd like something that looks more like this:</p>
  
  <pre><code>[
    [0] =&gt; ['post' =&gt; Doctrine PostEntity, 
            'post_author' =&gt; Doctrine UserEntity, 
            'post_liked' =&gt; Doctrine LikeEntity],
    [1] =&gt; ['post' =&gt; Doctrine PostEntity, 
            'post_author' =&gt; Doctrine UserEntity, 
            'post_liked' =&gt; Doctrine LikeEntity],
    ...
  ]
  </code></pre>
  
  <p>Were I only trying to load the author, it'd be fine because I could load the author value from the loaded post (Doctrine automatically hydrates the object with selected join data from the author table). For example:</p>
  
  <pre><code>$post = $result[0];
  $author = $post-&gt;getAuthor(); // Doctrine UserEntity
  </code></pre>
  
  <p>The issue comes up if I try to load a like for the current user. For example:</p>
  
  <pre><code>$post = $result[0];
  $like = $post-&gt;getLike(); // INVALID - there's no property "like" on Post
  $likes = $post-&gt;getLikes(); // valid, but loads the whole collection
  $like = $post-&gt;post_liked; // INVALID - the SQL alias is not a valid object property 
  </code></pre>
  
  <p>How do I access the data specified in the query?</p>