-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regression (5.17.2 -> 5.18.0): bug in aggregation with alias #11388
Comments
Did you enable the new |
@papb no, I didn't change anything. If aliases are not minified by default, the issue could be a side effect of this PR. I can confirm at least it works in 5.17.2 but not in 5.18.0 |
@frlinw Yeah I thought so but just wanted to make sure. The thing is, you put Minified alias issue in the title but the issue itself is only related to minification in the sense that it was the feature which introduced the bug. I will rename it to reduce confusion. |
One more thing, you posted a lot of code, is all of that really needed to reproduce the issue? Can you shorten it? Also, you have posted a code snippet that shows the problem but is not entirely self-contained (i.e. I can't just copy-paste it and run it), please provide a SSCCE (also known as MCVE/reprex) for it, thanks! |
Initially it was a question more than an issue, because I'm aware the direct use of aliases is not really a public thing so I wanted a supported way to access aliases (as I thought it was an alias issue). |
This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂 |
This issue has been automatically marked as stale because it has been open for 14 days without activity. It will be closed if no further activity occurs within the next 14 days. If this is still an issue, just leave a comment or remove the "stale" label. 🙂 |
This issue is still a thing await User.findAll({
attributes: [
'id',
[
Sequelize.fn('sum', Sequelize.col('missions->clientfile->invoice.totalTaxed')),
'totalRevenue'
]
],
include: [{
association: 'missions',
attributes: [],
include: [{
association: 'clientfile',
required: true,
attributes: [],
include: [{
association: 'invoice',
required: true,
attributes: []
}]
}]
}],
group: [
['id']
]
}) 5.17.2SELECT "User"."id", sum("missions->clientfile->invoice"."totalTaxed") AS "totalRevenue"
FROM "User" AS "User"
LEFT OUTER JOIN (
"Mission" AS "missions"
INNER JOIN "Clientfile" AS "missions->clientfile" ON "missions"."clientfileId" = "missions->clientfile"."id"
INNER JOIN "Invoice" AS "missions->clientfile->invoice" ON "missions->clientfile"."id" = "missions->clientfile->invoice"."clientfileId" )
ON "User"."id" = "missions"."technicianId" GROUP BY "User"."id"; 5.18.0 to 7.0.0-alpha.10SELECT "User"."id", sum("missions->clientfile->invoice"."totalTaxed") AS "totalRevenue"
FROM "User" AS "User"
LEFT OUTER JOIN (
"Mission" AS "missions"
INNER JOIN "Clientfile" AS "missions->clientfile" ON "missions"."clientfileId" = "missions->clientfile"."id"
INNER JOIN "Invoice" AS "missions->clientfile->invoice" ON "missions->clientfile"."id" = "missions->clientfile->invoice"."clientfileId"
) ON "User"."id" = "missions"."technicianId" GROUP BY "id" error: column reference "id" is ambiguous Dirty workaround
|
Issue Description
Before v5.18.0, it was possible to do some aggregation using alias name directly.
(Probably related to 3fcb2d2)
Question: is there an alternative official way to do the following request without using alias explicitly?
What are you doing?
What do you expect to happen?
It works until 5.18.0
What is actually happening?
the request respond with
column reference "id" is ambiguous
but I suppose it's related to alias explicitly used in the request (which are no longer valid).Environment
Issue Template Checklist
How does this problem relate to dialects?
Would you be willing to resolve this issue by submitting a Pull Request?
The text was updated successfully, but these errors were encountered: