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
Chained .joins incorrectly re-ordered during query #36558
Comments
I have tested this case with Rails what about your example it's sounds a little bit incorrect since what about issue related to order of |
I get this problem when using Example:
But
It obliterates the left join produced by I have another app where it is a bit more complicated, but seems to be adding the left join for |
This issue has been automatically marked as stale because it has not been commented on for at least three months. |
Steps to reproduce
Expected behavior
SELECT "users".* FROM "users" INNER JOIN "groups" ON "groups"."id" = "users"."group_id" AND groups.id = 1 LEFT OUTER JOIN "clubs" ON "clubs"."id" = "users"."clubs_id"
Actual behavior
SELECT "users".* FROM "users" INNER JOIN "groups" ON "groups"."id" = "users"."group_id" LEFT OUTER JOIN "clubs" ON "clubs"."id" = "users"."clubs_id" AND groups.id = 1
The second .joins (
joins('AND groups.id = 1')
) gets moved to the end of the chain, resulting in more users retrieved than expected. It becomes part of theLEFT OUTER JOIN
, meaning that it is not used as a filter.System configuration
Tested to be an issue on:
Ruby version: 2.6.3
Also tested on Ruby 2.5.1
Rails version: 6.0.0.rc1
Also tested on Rails 5.2.3
More information
Although a separate problem, I noticed issue #34328 and wonder if the issues are related.
The text was updated successfully, but these errors were encountered: