diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2016-07-27 20:31:38 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-27 20:31:38 -0400 |
commit | a64d9835f11ea7919fae825bceb91e08a1480766 (patch) | |
tree | 54afe354300e7842a96e413e77045b6313315eec /activerecord | |
parent | 2a095142fb2f3300c841cf3a15100581635f4a35 (diff) | |
parent | 28c29973aa143735333f658910b882cf265db692 (diff) | |
download | rails-a64d9835f11ea7919fae825bceb91e08a1480766.tar.gz rails-a64d9835f11ea7919fae825bceb91e08a1480766.tar.bz2 rails-a64d9835f11ea7919fae825bceb91e08a1480766.zip |
Merge pull request #25702 from k0kubun/joins-circular-reference
Remove circular join references in join_dependency
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency/join_association.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/scoping/relation_scoping_test.rb | 7 |
2 files changed, 10 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency/join_association.rb b/activerecord/lib/active_record/associations/join_dependency/join_association.rb index c5fbe0d1d1..bdf77009eb 100644 --- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb +++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb @@ -56,7 +56,9 @@ module ActiveRecord klass_scope = if klass.current_scope - klass.current_scope.clone + klass.current_scope.clone.tap { |scope| + scope.joins_values = [] + } else relation = ActiveRecord::Relation.create( klass, diff --git a/activerecord/test/cases/scoping/relation_scoping_test.rb b/activerecord/test/cases/scoping/relation_scoping_test.rb index c15d57460b..ef46fd5d9a 100644 --- a/activerecord/test/cases/scoping/relation_scoping_test.rb +++ b/activerecord/test/cases/scoping/relation_scoping_test.rb @@ -228,6 +228,13 @@ class RelationScopingTest < ActiveRecord::TestCase assert SpecialComment.all.any? end end + + def test_circular_joins_with_current_scope_does_not_crash + posts = Post.joins(comments: :post).scoping do + Post.current_scope.first(10) + end + assert_equal posts, Post.joins(comments: :post).first(10) + end end class NestedRelationScopingTest < ActiveRecord::TestCase |