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, |
rafaelfranca
Jan 31, 2017
Member
The indentation is wrong here now.
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: |
rafaelfranca
Jan 31, 2017
Member
No need for a nodoc here.
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" |
rafaelfranca
Jan 31, 2017
Member
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.
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.
Hey @rafaelfranca, I've made the changes and squashed. |
afd7c66
@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
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.