title: How can i select extra fields and map them to entity via doctrine query builder in symfony?
body: <p>I have two entities: Category and Product. Category entity has not link to Product <code>(protected $products // ArrayColection)</code>. I need to calculate total amount of product prices inside each category, and i need to do it ONLY IN SINGLE request via query builder.</p>
  
  <p>Can i do something like this:</p>
  
  <pre><code>$categories = $categoryRepository-&gt;createQueryBuilder('c')-&gt;join('AppBundle:Product', 'p')-&gt;addSelect('SUM(p.price) as c.totalPrice')-&gt;addGroupBy('c.id')-&gt;getQuery()-&gt;getResults();
  </code></pre>
  
  <p>And then map attribute <code>totalPrice</code> to entity, to have access to it somehow like this:</p>
  
  <pre><code>$categories-&gt;get(0)-&gt;totalAmount
  </code></pre>
  
  <p>I CAN'T build extra query, and i CAN'T add relationsip field to Category ($products) to calculte totalSum in entity method by adding price of each product. I should done it only with single query...</p>