title: Doctrine INDEX BY foreign key
body: <p>I am trying to get summary data for articles from article_stats table indexed with article ids.</p>
  
  <p>The query builder looks like this:</p>
  
  <pre><code>$qb = $this-&gt;articlesStatsRepository-&gt;createQueryBuilder('ass');
  $qb-&gt;select('SUM(ass.pageviews)')
      -&gt;indexBy('ass', 'ass.article') // this doesnt work
      -&gt;groupBy('ass.article');
  
  $articleStats = $query-&gt;getResult();
  </code></pre>
  
  <p>This results in query</p>
  
  <pre><code>SELECT SUM(ass.pageviews) 
  FROM AppBundle\Entity\ArticleStats ass 
  INDEX BY ass.article 
  GROUP BY ass.article
  </code></pre>
  
  <p>With an error of:</p>
  
  <pre><code>[Semantical Error] near 'article GROUP': 
  Error: Invalid PathExpression. Must be a StateFieldPathExpression.
  </code></pre>
  
  <p>I've tried <code>-&gt;indexBy('ass', 'IDENTITY(ass.article)')</code> but that didn't work either.</p>
  
  <p>So how can I select data from database indexed by foreign key?</p>