Doctrine orm 如何使用条令处理混合结果

Doctrine orm 如何使用条令处理混合结果,doctrine-orm,query-builder,Doctrine Orm,Query Builder,我正在使用symfony2和查询生成器。下面的查询结果是混合结果。我知道这是因为在SELECT中使用聚合函数,但我没有找到任何其他方法,这正是我所需要的。如有任何指示,将不胜感激: public function Inventory() { $em = $this->getEntityManager(); $qb = $em->createQueryBuilder(); $qb ->add('select', 'i.id, i.name,

我正在使用symfony2和查询生成器。下面的查询结果是混合结果。我知道这是因为在SELECT中使用聚合函数,但我没有找到任何其他方法,这正是我所需要的。如有任何指示,将不胜感激:

public function Inventory() {
    $em = $this->getEntityManager();
    $qb = $em->createQueryBuilder();
    $qb
        ->add('select', 'i.id, i.name, SUM(pod.quantityorder) as quantityordered, SUM(it.quantity) as quantityreceived')
        ->add('from', 'AutokeenPurchasingBundle:Items i')
        ->leftJoin('i.purchase_order_details', 'pod')
        ->leftJoin('i.inventory_transactions', 'it', 'WITH', 'it.inventory_transaction_type = 1')
        ->add('groupBy', 'i.id')
        ->addGroupBy('it.item')
        ->addGroupBy('pod.item')
        ->add('orderBy', 'i.id');
    $query = $qb->getQuery();
    $query->useResultCache('my_cache_id');
    return $result = $query->getScalarResult();
}

我确实是自己用本机SQL解决的:)