提交 f3f65282 编写于 作者: R Ryuta Kamizono

Fix crashing on circular left join references with scoping

Follow up of #25702.
上级 3a628b93
...@@ -199,7 +199,7 @@ def join_scopes(table, predicate_builder) # :nodoc: ...@@ -199,7 +199,7 @@ def join_scopes(table, predicate_builder) # :nodoc:
def klass_join_scope(table, predicate_builder) # :nodoc: def klass_join_scope(table, predicate_builder) # :nodoc:
if klass.current_scope if klass.current_scope
klass.current_scope.clone.tap { |scope| klass.current_scope.clone.tap { |scope|
scope.joins_values = [] scope.joins_values = scope.left_outer_joins_values = [].freeze
} }
else else
relation = ActiveRecord::Relation.create( relation = ActiveRecord::Relation.create(
......
...@@ -229,12 +229,19 @@ def test_current_scope_does_not_pollute_sibling_subclasses ...@@ -229,12 +229,19 @@ def test_current_scope_does_not_pollute_sibling_subclasses
end end
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 posts = Post.joins(comments: :post).scoping do
Post.current_scope.first(10) Post.first(10)
end end
assert_equal posts, Post.joins(comments: :post).first(10) assert_equal posts, Post.joins(comments: :post).first(10)
end 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 end
class NestedRelationScopingTest < ActiveRecord::TestCase class NestedRelationScopingTest < ActiveRecord::TestCase
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册