Skip to content

Fix eager load with Arel joins to maintain the original joins order #39305

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

Merged
merged 1 commit into from
May 16, 2020

Conversation

kamipo
Copy link
Member

@kamipo kamipo commented May 16, 2020

#38354 is caused by #36304, to fix invalid joins order for through
associations.

Actually passing Arel joins to joins is not officially supported
unlike string joins, and also Arel joins could be easily converted to
string joins by to_sql. But I'd not intend to break existing apps
without deprecation cycle, so I've changed to mark only implicit joins
as leading joins, to maintain the original joins order for user supplied
Arel joins.

Fixes #38354.

rails#38354 is caused by rails#36304, to fix invalid joins order for through
associations.

Actually passing Arel joins to `joins` is not officially supported
unlike string joins, and also Arel joins could be easily converted to
string joins by `to_sql`. But I'd not intend to break existing apps
without deprecation cycle, so I've changed to mark only implicit joins
as leading joins, to maintain the original joins order for user supplied
Arel joins.

Fixes rails#38354.
@kamipo kamipo merged commit dec12b5 into rails:master May 16, 2020
@kamipo kamipo deleted the fix_eager_load_with_arel_joins branch May 16, 2020 09:42
kamipo added a commit that referenced this pull request May 16, 2020
Fix eager load with Arel joins to maintain the original joins order
@j15e
Copy link

j15e commented Jun 1, 2020

This change seems to cause some combination of scope merge to generate invalid SQL because the joins ordering is now invalid. I get a ActiveRecord::StatementInvalid Exception: PG::UndefinedTable: ERROR: missing FROM-clause entry for table "table_123 error.

When I compare before / after this commit, looks like the only change is one of the join is now the very first join (which doesn't work) and before it was in a "correct" order. I have a chain of two table joined like library -> book -> author and the author join is placed before the book join.

@kamipo
Copy link
Member Author

kamipo commented Jun 2, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Eager load order bug with Arel joins after update to Rails 6
2 participants