You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SELECTc.id_contract,
COALESCE(credit.total_credit, 0) AS total_credit,
COALESCE(debit.total_debit, 0) AS total_debit,
COALESCE(credit.total_credit, 0) + COALESCE(debit.total_debit, 0) AS current_balance
FROM
contracts c
LEFT JOIN (
SELECT id_contract, SUM(amount) AS total_credit
FROM credit_operations
GROUP BY id_contract
) credit ONc.id_contract=credit.id_contractLEFT JOIN (
SELECT id_contract, SUM(amount) AS total_debit
FROM debit_operations
GROUP BY id_contract
) debit ONc.id_contract=debit.id_contract;
With FluentPDO, it's may be done with the following code :
$query = $fpdo -> from('contracts')
-> select("COALESCE(credit.total_credit, 0) AS total_credit")
-> select("COALESCE(debit.total_debit, 0) AS total_debit")
-> select("COALESCE(credit.total_credit, 0) + COALESCE(debit.total_debit, 0) AS current_balance")
-> disableSmartJoin()
-> leftJoin(
"( SELECT id_contract, SUM(value) AS total_credit FROM credit_operations GROUP BY id_contract ) credit ON admin_contract.id_contract = credit.id_contract")
-> leftJoin(
"( SELECT id_contract, SUM(cost) AS total_debit FROM debit_operations GROUP BY id_contract ) debit ON admin_contract.id_contract = debit.id_contract")
To day, it's not working, because the second JOIN clause is ignored :
echo($query->getQuery());
SELECT contracts.*, COALESCE(credit.total_credit, 0) AS total_credit, COALESCE(debit.total_debit, 0) AS total_debit, COALESCE(credit.total_credit, 0) + COALESCE(debit.total_debit, 0) AS solde
FROM contracts
LEFTJOIN (
SELECT id_contract, SUM(value) AS total_credit
FROM credit_operations
WHERE valid = TRUE
GROUPBY id_contract
) credit ON contracts.id_contract = credit.id_contract
It's due to the method Envms\FluentPDO\Regex::tableAlias() that does not handle this case.
Hello,
I need to make a complex query like this one :
With FluentPDO, it's may be done with the following code :
To day, it's not working, because the second JOIN clause is ignored :
It's due to the method
Envms\FluentPDO\Regex::tableAlias()
that does not handle this case.A quick fix could be :
What do you think about this fix ?
Note: The
tableAlias()
method seem currently only used byEnvms\FluentPDO\Queries\Common::setJoinNameAlias()
.The text was updated successfully, but these errors were encountered: