我有一个实体Client
和Facture
,每个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.
我收到此错误
{{1}}
答案 0 :(得分:1)
尝试改变这个:
->select('f.clientId','count(f.clientId) as factures','c.name')
到此:
->select('IDENTITY(f.clientId)','count(f.clientId) as factures','c.name')
您可以使用IDENTITY函数在查询中选择外键ID