Skip to content
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

Joining more than 3 tables in a row and merging scopes crashes #15488

Closed
SebastianZaha opened this issue Jun 3, 2014 · 3 comments
Closed

Joining more than 3 tables in a row and merging scopes crashes #15488

SebastianZaha opened this issue Jun 3, 2014 · 3 comments

Comments

@SebastianZaha
Copy link

As seen in attached gist, I have created 5 tables, connected by belongs_to one to one relationships.

Joining 3 of them in order works fine, joining the 4th one yields an incorrect sql query, where the table join order is wrong, and joining 4 of them raises an ActiveRecord::ConfigurationError

I initially thought it is related to #15461 but I tried the patch and it does not solve this issue, so it might be a separate problem.

@SebastianZaha
Copy link
Author

@thedarkone
Copy link
Contributor

It is related to #15461: you found another place (in ActiveRecord::Relation::Merger#merge_joins) where AR wasn't preserving JOIN clause order. I'll modify #15461 to fix this bug as well.

As for ActiveRecord::ConfigurationError its tiny bug in ActiveRecord::Relation::Merger#merge_joins, this will get rid of it:

- relation.joins! rest
+ relation.joins! *rest

I will also fix that in #15461.

thedarkone added a commit to thedarkone/rails that referenced this issue Jun 6, 2014
JOIN clauses order is important, previous implementation always
put string or arel joins at then end (after auto-generated
association joins).

Fixes rails#12953, rails#15488.
thedarkone added a commit to thedarkone/rails that referenced this issue Sep 12, 2014
JOIN clauses order is important, previous implementation always
put string or arel joins at then end (after auto-generated
association joins).

Fixes rails#12953, rails#15488, rails#16635.
@rails-bot rails-bot added the stale label Jan 2, 2015
@rails-bot
Copy link

This issue has been automatically marked as stale because it has not been commented on for at least
three months.

The resources of the Rails team are limited, and so we are asking for your help.

If you can still reproduce this error on the 4-1-stable, 4-0-stable branches or on master,
please reply with all of the information you have about it in order to keep the issue open.

Thank you for all your contributions.

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

No branches or pull requests

5 participants