Error: Invalid PathExpression when using Left Join with Count with Query-Builder in Symfony3 ( Doctrine2)

Error: Invalid PathExpression when using Left Join with Count with Query-Builder in Symfony3 ( Doctrine2)

我有一个实体 ClientFacture ,每个 Client 有很多 Facture (:ManyToOne 关系使用由 Facture->Clientid 表示的外键, 我想列出所有 Client 以及他拥有的 Facture 的数量。

   ////////////////////////////////
   // id //  name   // factures  //
   ////////////////////////////////
   // 2  // someone // 16        //
   ////////////////////////////////

我试图实现的 SQL 逻辑将是这样的:

SELECT c.name as name , f.client_id, Count(*) as factures
FROM facture as f INNER JOIN client as c
ON f.client_id = c.id 
WHERE f.client_id != 0 AND c.state = 1
GROUP BY c.id

到目前为止,我使用查询生成器所做的是 FactureRepository 上的以下内容,它只识别 Facture 实体。

public function findactivityList()
{  
return $this->createQueryBuilder('f')
->select('f.clientId','count(f.clientId) as factures','c.name')
->leftJoin('servicomBundle:FComptet ','c','WITH' ,'f.clientId = c.id')
->where('f.clientId != 0')
->andWhere('c.state = 1')
->groupBy('f.clientId')
->getQuery()
->execute()
;     
}

我收到这个错误

[Semantical Error] line 0, col 9 near 'clientId, count(f.clientId)': Error: Invalid PathExpression. Must be a StateFieldPathExpression.

尝试改变这个:

->select('f.clientId','count(f.clientId) as factures','c.name')

对此:

->select('IDENTITY(f.clientId)','count(f.clientId) as factures','c.name')

您可以使用 IDENTITY 函数 select 查询中的外键 ID