我有这个实体:
Invoice hasMany PlannedCharge
PlannedCharge hasMany PartialCharge
我需要知道发票是否已全额支付,以下 sql 也是如此:
SELECT
Invoice.id
FROM
webfactory_sale_invoices Invoice
AND
0 <>
((SELECT
SUM(PlannedCharge.ammount)
FROM
webfactory_sale_planned_charges PlannedCharge
WHERE
PlannedCharge.invoice_id = Invoice.id
GROUP BY Invoice.id) - IFNULL((SELECT
SUM(PartialCharge.ammount)
FROM
webfactory_sale_planned_charges PlannedCharge
INNER JOIN
webfactory_sale_partial_charges PartialCharge ON PlannedCharge.id = PartialCharge.planned_charge_id
WHERE
PlannedCharge.invoice_id = Invoice.id
GROUP BY Invoice.id), 0))
现在,通过 querybuilder 以这种方式转换为 DQL:
$qb->andWhere($qb->expr()->neq(0, $qb->expr()->diff(
$qb->select('SUM(PlannedCharge.ammount)')
->from('WebFactorySaleBundle:PlannedCharge', 'PlannedCharge')
->where("PlannedCharge.invoice = {$invoiceAlias}")
->groupBy($invoiceAlias)
,
$qb->select('SUM(PartialCharge.ammount)')
->from('WebFactorySaleBundle:PlannedCharge', 'PlannedCharge')
->innerJoin('WebFactorySaleBundle:PartialCharge', 'PartialCharge')
->where("PlannedCharge.invoice = {$invoiceAlias}")
->groupBy($invoiceAlias)
)
));
我收到错误消息:致命错误:达到“100”的最大函数嵌套级别,正在中止!
我怎么写这个查询?