title: how to handle mixed results using doctrine
body: <p>I am using symfony2 and Query builder. I get mixed results as a result of my query that follows. I know this is due to using aggregate functions in SELECT, but I DO NOT find any other way and this is exactly what I need. Any direction would be gratefully appreciated:</p>
  
  <pre><code>public function Inventory() {
      $em = $this-&gt;getEntityManager();
      $qb = $em-&gt;createQueryBuilder();
      $qb
          -&gt;add('select', 'i.id, i.name, SUM(pod.quantityorder) as quantityordered, SUM(it.quantity) as quantityreceived')
          -&gt;add('from', 'AutokeenPurchasingBundle:Items i')
          -&gt;leftJoin('i.purchase_order_details', 'pod')
          -&gt;leftJoin('i.inventory_transactions', 'it', 'WITH', 'it.inventory_transaction_type = 1')
          -&gt;add('groupBy', 'i.id')
          -&gt;addGroupBy('it.item')
          -&gt;addGroupBy('pod.item')
          -&gt;add('orderBy', 'i.id');
      $query = $qb-&gt;getQuery();
      $query-&gt;useResultCache('my_cache_id');
      return $result = $query-&gt;getScalarResult();
  }
  </code></pre>