aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-09-07 09:26:02 +0100
committerJon Leighton <j@jonathanleighton.com>2011-09-07 09:27:41 +0100
commit143769051bcf5b3a7600744be2d8db6e9c859288 (patch)
tree220be95b653bf31119a709b6974cac2ecdad02f8
parentdb8d54ebf5102d2f30c0c332ea852ad284702ef3 (diff)
downloadrails-143769051bcf5b3a7600744be2d8db6e9c859288.tar.gz
rails-143769051bcf5b3a7600744be2d8db6e9c859288.tar.bz2
rails-143769051bcf5b3a7600744be2d8db6e9c859288.zip
Don't include any of includes, preload, joins, eager_load in the through association scope.
-rw-r--r--activerecord/lib/active_record/associations/through_association.rb2
-rw-r--r--activerecord/test/cases/associations/nested_through_associations_test.rb8
2 files changed, 6 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations/through_association.rb b/activerecord/lib/active_record/associations/through_association.rb
index b010b5e9ef..b347a94978 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, :preload)
+ except(:select, :create_with, :includes, :preload, :joins, :eager_load)
)
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 6122098623..530f5212a2 100644
--- a/activerecord/test/cases/associations/nested_through_associations_test.rb
+++ b/activerecord/test/cases/associations/nested_through_associations_test.rb
@@ -356,11 +356,13 @@ 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
+ def test_joins_and_includes_from_through_models_not_included_in_association
prev_default_scope = Club.default_scopes
- Club.default_scopes = [Club.preload(:category)]
- assert_equal categories(:general), members(:groucho).club_category
+ [:includes, :preload, :joins, :eager_load].each do |q|
+ Club.default_scopes = [Club.send(q, :category)]
+ assert_equal categories(:general), members(:groucho).reload.club_category
+ end
ensure
Club.default_scopes = prev_default_scope
end