diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-06-11 07:57:26 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-06-11 08:11:39 +0900 |
commit | a81d47aa413bb31b06b1b8b22411a49a2b119a0e (patch) | |
tree | e6acd0a0e66609154de30f435979e70fdf91c277 /activerecord | |
parent | fcfe29cd2641b2ce3c01bc13f39d617ec302fc8d (diff) | |
download | rails-a81d47aa413bb31b06b1b8b22411a49a2b119a0e.tar.gz rails-a81d47aa413bb31b06b1b8b22411a49a2b119a0e.tar.bz2 rails-a81d47aa413bb31b06b1b8b22411a49a2b119a0e.zip |
Fix alias confliction when joining same table on has many through with left_joins
This regression was caused by #30995 due to `Hash#fetch` won't invoke
default proc. Just revert the change since #30995 is completely fixed by
e9c1653.
Fixes #33048.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/associations/alias_tracker.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/associations/has_many_through_associations_test.rb | 4 |
2 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/alias_tracker.rb b/activerecord/lib/active_record/associations/alias_tracker.rb index 4f3893588e..272eede824 100644 --- a/activerecord/lib/active_record/associations/alias_tracker.rb +++ b/activerecord/lib/active_record/associations/alias_tracker.rb @@ -33,7 +33,7 @@ module ActiveRecord elsif join.is_a?(Arel::Nodes::Join) join.left.name == name ? 1 : 0 elsif join.is_a?(Hash) - join.fetch(name, 0) + join[name] else raise ArgumentError, "joins list should be initialized by list of Arel::Nodes::Join" end diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb index 46fa36d7dd..d5573b6d02 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -1289,6 +1289,10 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase assert_equal authors(:david), Author.joins(:comments_for_first_author).take end + def test_has_many_through_with_left_joined_same_table_with_through_table + assert_equal [comments(:eager_other_comment1)], authors(:mary).comments.left_joins(:post) + end + def test_has_many_through_with_unscope_should_affect_to_through_scope assert_equal [comments(:eager_other_comment1)], authors(:mary).unordered_comments end |