Skip to content

Commit

Permalink
Remove circular join references in join_dependency
Browse files Browse the repository at this point in the history
Fixes #25653.
  • Loading branch information
k0kubun committed Aug 13, 2016
1 parent c55a5d6 commit ce271ce
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def join_constraints(foreign_table, foreign_klass, node, join_type, tables, scop

klass_scope =
if klass.current_scope
klass.current_scope.clone
klass.current_scope.clone.tap { |scope|
scope.joins_values = []
}
else
klass.send(:build_default_scope, ActiveRecord::Relation.create(klass, table))
end
Expand Down
7 changes: 7 additions & 0 deletions activerecord/test/cases/scoping/relation_scoping_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@ def test_delete_all_default_scope_filters_on_joins
assert_equal [], DeveloperFilteredOnJoins.all
assert_not_equal [], Developer.all
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
Expand Down

0 comments on commit ce271ce

Please sign in to comment.