title: How can I select count(field) and still get an object with createQueryBuilder
body: <p>I want to access a query result in twig as a whole object. In the query however, I want to select just several fields from the tables <strong>+ count</strong>. In my example I have a company, which is owned by an owner and has several employees. I want to create a query, which gives me a list of companies ordered by count of their employees.</p>
  
  <pre><code>$qb = $this-&gt;createQueryBuilder('c');
  $qb-&gt;select('count(e.id), partial c.{id, name}, partial o.{id, name}');
  $qb-&gt;leftJoin('c.employees', 'e');
  $qb-&gt;innerJoin('c.owner', 'o');
  $qb-&gt;groupBy('c.id');
  </code></pre>
  
  <p>The query works fine, however I get an error, when I want to access other objects liked with normaly in the company entity (there is an collection of image entities, and each image entity contains the path to the image). The query does not load the whole company entity with its dependencies... I cannot acces the "firstImage" method, which returns the first image from the collection. I get this error</p>
  
  <blockquote>
    <p>Key "firstImage" for array with keys "0, 1" does not exist in
    MyBundle:List:results.html.twig at line 6</p>
  </blockquote>
  
  <p>Note that leaving out the "employees count" makes it whole work.</p>
  
  <pre><code>$qb = $this-&gt;createQueryBuilder('c');
  $qb-&gt;select('partial c.{id, name}, partial o.{id, name}');
  $qb-&gt;leftJoin('c.employees', 'e');
  $qb-&gt;innerJoin('c.owner', 'o');
  $qb-&gt;groupBy('c.id');
  </code></pre>