添加从Entity,Symfony中的连接表字段中选择

时间:2016-02-24 10:56:17

标签: symfony doctrine-query

当我跑步时:

{
  "rules": {
    "updates": {
      "$location_id": { // $location_id should act like a wild card
        ".indexOn": ["validFrom"]
      }
    }
  }
}

它产生以下结构:

$this->createQueryBuilder('debtor')
->join('debtor.deals', 'deal')
->addSelect('...something... as closed_deals_count')
->getQuery()
->getSingleResult()

我怎么能用' closed_deals_count'来获得单一的债务人记录?在它而不是数组?

1 个答案:

答案 0 :(得分:0)

我认为你正在寻找getSingleScalarResult。类似的东西:

$this->createQueryBuilder('debtor')
->join('debtor.deals', 'deal')
->addSelect('COUNT(deal.id) as closed_deals_count')
->getQuery()
->getSingleScalarResult()