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
Fix relation merger issue with left_outer_joins
.
#27860
Fix relation merger issue with left_outer_joins
.
#27860
Conversation
r? @pixeltrix (@rails-bot has picked a reviewer for you, use r? to override) |
|
||
join_dependency = ActiveRecord::Associations::JoinDependency.new(other.klass, | ||
join_dependency = ActiveRecord::Associations::JoinDependency.new(other.klass, | ||
joins_dependency, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation is wrong here now.
# First one is an `ActiveRecord::Associations::JoinDependency` | ||
# and the second one is an array of joinable objects | ||
# other than Hash, Symbol, Array. | ||
def partition_join_dependencies(values) # :nodoc: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for a nodoc here.
else | ||
raise ArgumentError, "only Hash, Symbol and Array are allowed" | ||
raise ArgumentError, "only Hash, Symbol, Array and JoinDependency are allowed" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JoinDependency is not public API and we don't want users to be using it in their applications so we should not talk about it here.
c9b98ce
to
69b3d17
Compare
Hey @rafaelfranca, I've made the changes and squashed. |
7633276
to
afd7c66
Compare
@rafaelfranca does this still need work? I think all changes done. |
@meinac @rafaelfranca any idea why this PR hasn't been merged in yet? I'm still facing this issue on Rails 5.0.6 / mysql |
@rohpai I don't really know why this is not merged yet, I don't have write access to Rails repositories, if Rails team wants to merge this I can rebase and resolve conflicts again. |
Can you rebase? |
afd7c66
to
899a801
Compare
done! There is a bit duplications between |
The problem: If you want to merge a relation which contains
left_outer_joins
to another relation, AR tries to do left_outer_joins with base relation which is incorrect behaviour.Here is the test script you can see current behaviour;
Without this pr, AR tries to join Preference model with Post model and raises exception because there is no relation declared between Preference and Post directly.
Using merge to share logic between scopes are the best way to keep models clean so this is why I think this should work as expected. Btw I think this is not a regression since
left_outer_joins
presented. I think it is just forgotten.