Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove circular join references in join_dependency #25702

Merged
merged 1 commit into from Jul 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -56,7 +56,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
relation = ActiveRecord::Relation.create(
klass,
Expand Down
7 changes: 7 additions & 0 deletions activerecord/test/cases/scoping/relation_scoping_test.rb
Expand Up @@ -228,6 +228,13 @@ def test_current_scope_does_not_pollute_sibling_subclasses
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
Expand Down