Nested through associations: preloads from the default scope of a through model should not be included in the association scope. (We're already excluding includes.) Fixes #2834.

This commit is contained in:
Jon Leighton
2011-09-06 16:34:32 +01:00
parent b24d668859
commit 9bde73ff72
2 changed files with 10 additions and 1 deletions

View File

@@ -16,7 +16,7 @@ module ActiveRecord
chain[1..-1].each do |reflection|
scope = scope.merge(
reflection.klass.scoped.with_default_scope.
except(:select, :create_with, :includes)
except(:select, :create_with, :includes, :preload)
)
end
scope

View File

@@ -356,6 +356,15 @@ class NestedThroughAssociationsTest < ActiveRecord::TestCase
assert_equal categories(:general), members(:groucho).club_category
end
def test_has_one_through_has_one_through_with_belongs_to_source_reflection_with_default_scope_preload_on_the_through_model
prev_default_scope = Club.default_scopes
Club.default_scopes = [Club.preload(:category)]
assert_equal categories(:general), members(:groucho).club_category
ensure
Club.default_scopes = prev_default_scope
end
def test_has_one_through_has_one_through_with_belongs_to_source_reflection_preload
members = assert_queries(4) { Member.includes(:club_category).to_a.sort_by(&:id) }
general = categories(:general)