-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Adding an includes
to a query in Rails 5.2 adds a LEFT OUTER JOIN that breaks with pluck
#32701
Comments
Now that you have the script and the version where it passes it should not be hard to use |
Yup! Doing that right now. |
Thank you! |
This is the commit that broke the above test case: 249ddd0 |
includes
to a query in Rails 5.2 adds a LEFT OUTER JOIN unexpectedlyincludes
to a query in Rails 5.2 adds a LEFT OUTER JOIN that breaks with pluck
I think this => #32856 is a duplicate |
The test case I presented in #32856 fails as well with v 5.1.4 unlike this one |
I have a simpler test case for a related error that I strongly suspect is caused by the same commit, although I haven't bisected. Gist: https://gist.github.com/eostrom/46ab1773b84e6c440f0ece028aa1e063 In my case, no # Post has_many :comments
# Comment belongs_to :post
Post.joins(:comments).merge(Comment.joins(:post)) In Rails 5.1.6 (Ruby 2.5.1p57), this generates SQL that gives "Comment's posts" its own alias: SELECT "posts".* FROM "posts"
INNER JOIN "comments"
ON "comments"."post_id" = "posts"."id"
LEFT OUTER JOIN "posts" "posts_comments"
ON "posts_comments"."id" = "comments"."post_id" In Rails 5.2.0, it was changed to generate an INNER JOIN, but the alias was lost, so it raises a "not unique table/alias" error (or "ambiguous column name" in SQLite): SELECT "posts".* FROM "posts"
INNER JOIN "comments"
ON "comments"."post_id" = "posts"."id"
INNER JOIN "posts"
ON "posts"."id" = "comments"."post_id" (This is a contrived example, of course. In my real application, I'm building a complex scope on Let me know if this should be filed as a separate issue. |
Fixed by #33066. |
The below test case passes on Rails 5.1.4. Let me know if I'm missing something obvious in the release notes that would explain why this would fail in 5.2 😄
Steps to reproduce
Expected behavior
Adding the
includes
shouldn't affect the resulting query.Note: The
pluck
is needed to get this query to fail. Otherwise, it runs fine.Actual behavior
Adding the
includes
adds an extraLEFT OUTER JOIN
to the resulting query. With thepluck
, it ends up throwing a "Not unique table/alias" error.System configuration
Rails version: 5.2.0
Ruby version: 2.3.3
The text was updated successfully, but these errors were encountered: