提交 6db27ce0 编写于 作者: M Matthew Draper 提交者: GitHub

Merge pull request #29181 from kamipo/fix_circular_left_joins_with_scoping

Fix crashing on circular left join references with scoping
......@@ -199,7 +199,7 @@ def join_scopes(table, predicate_builder) # :nodoc:
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(
......
......@@ -229,12 +229,19 @@ def test_current_scope_does_not_pollute_sibling_subclasses
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册