aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-09-06 16:34:32 +0100
committerJon Leighton <j@jonathanleighton.com>2011-09-06 16:34:32 +0100
commit9bde73ff72812f6f3c59ad97be6ca6c628e109ea (patch)
treec3f6c81e620b5862f6b2d4519471dd22e738b8da /activerecord
parentb24d668859c5836c0e3ed277b2022a1a39eb3f8e (diff)
downloadrails-9bde73ff72812f6f3c59ad97be6ca6c628e109ea.tar.gz
rails-9bde73ff72812f6f3c59ad97be6ca6c628e109ea.tar.bz2
rails-9bde73ff72812f6f3c59ad97be6ca6c628e109ea.zip
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.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations/through_association.rb2
-rw-r--r--activerecord/test/cases/associations/nested_through_associations_test.rb9
2 files changed, 10 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/through_association.rb b/activerecord/lib/active_record/associations/through_association.rb
index 81172179e0..b010b5e9ef 100644
--- a/activerecord/lib/active_record/associations/through_association.rb
+++ b/activerecord/lib/active_record/associations/through_association.rb
@@ -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
diff --git a/activerecord/test/cases/associations/nested_through_associations_test.rb b/activerecord/test/cases/associations/nested_through_associations_test.rb
index 80c6e41169..6122098623 100644
--- a/activerecord/test/cases/associations/nested_through_associations_test.rb
+++ b/activerecord/test/cases/associations/nested_through_associations_test.rb
@@ -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)