diff options
author | Matthew Draper <matthew@trebex.net> | 2017-05-25 09:54:06 +0930 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-25 09:54:06 +0930 |
commit | 6db27ce0946a8c4072b49c4b203811e5751ad406 (patch) | |
tree | 33288b9d87b7e3236b79ee79000598ca8819e252 | |
parent | c7dd4a7a9f20216091399a30a9750a8cf598798e (diff) | |
parent | f3f652827f1db772741d56664cd3fb583873d0cd (diff) | |
download | rails-6db27ce0946a8c4072b49c4b203811e5751ad406.tar.gz rails-6db27ce0946a8c4072b49c4b203811e5751ad406.tar.bz2 rails-6db27ce0946a8c4072b49c4b203811e5751ad406.zip |
Merge pull request #29181 from kamipo/fix_circular_left_joins_with_scoping
Fix crashing on circular left join references with scoping
-rw-r--r-- | activerecord/lib/active_record/reflection.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/scoping/relation_scoping_test.rb | 11 |
2 files changed, 10 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 1a9e0a4a40..65fdbc2fe4 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -199,7 +199,7 @@ module ActiveRecord def klass_join_scope(table, predicate_builder) # :nodoc: if klass.current_scope klass.current_scope.clone.tap { |scope| - scope.joins_values = [] + scope.joins_values = scope.left_outer_joins_values = [].freeze } else relation = ActiveRecord::Relation.create( diff --git a/activerecord/test/cases/scoping/relation_scoping_test.rb b/activerecord/test/cases/scoping/relation_scoping_test.rb index 3fbff7664b..8535be8402 100644 --- a/activerecord/test/cases/scoping/relation_scoping_test.rb +++ b/activerecord/test/cases/scoping/relation_scoping_test.rb @@ -229,12 +229,19 @@ class RelationScopingTest < ActiveRecord::TestCase end end - def test_circular_joins_with_current_scope_does_not_crash + def test_circular_joins_with_scoping_does_not_crash posts = Post.joins(comments: :post).scoping do - Post.current_scope.first(10) + Post.first(10) end assert_equal posts, Post.joins(comments: :post).first(10) end + + def test_circular_left_joins_with_scoping_does_not_crash + posts = Post.left_joins(comments: :post).scoping do + Post.first(10) + end + assert_equal posts, Post.left_joins(comments: :post).first(10) + end end class NestedRelationScopingTest < ActiveRecord::TestCase |