title: Create a group by query with inner join using Doctrine Query Builder
body: <p>I struggle to create a query to get information from two tables. I want to count rows and group it by category and type.</p>
  
  <p>My normal PostgresSQL query looks like this:</p>
  
  <pre><code>SELECT c.name AS category_name, i.type, count(i) AS number_of_items
  FROM item i
  INNER JOIN category c
  ON i.category_id = c.id
  GROUP BY c.name, i.type
  </code></pre>
  
  <p>How do I build this query using Doctrine Query Builder?</p>
  
  <p>What I have tried:</p>
  
  <pre><code>$qb-&gt;select(['c.name', 'i.type', 'count(i)'])
      -&gt;from('AppBundle:Item', 'i')
      -&gt;innerJoin('i', 'AppBundle:Category', 'c', 'i.category_id = c.id')
      -&gt;groupBy('c.name')
      -&gt;groupBy('i.type');
  
  return $qb-&gt;getQuery()-&gt;getResult();
  </code></pre>
  
  <p>But this give me an error:</p>
  
  <blockquote>
    <p>[Semantical Error] line 0, col 80 near 'i AppBundle:Category':
    Error: Class 'i' is not defined.</p>
  </blockquote>
  
  <p>I'm trying to follow the principle in the documentation found here: <a href="http://doctrine-orm.readthedocs.io/projects/doctrine-dbal/en/latest/reference/query-builder.html#join-clauses" rel="nofollow noreferrer">http://doctrine-orm.readthedocs.io/projects/doctrine-dbal/en/latest/reference/query-builder.html#join-clauses</a></p>
  
  <p>Any help would be appreciated.</p>