Permalink
Browse files

Don't include any of includes, preload, joins, eager_load in the thro…

…ugh association scope.
  • Loading branch information...
1 parent 9198c7a commit df21e3d7f7848361414de5b844f0fcb2bc7b88ae @jonleighton jonleighton committed Sep 7, 2011
View
@@ -4,8 +4,8 @@
prepared statments on the database. The limit defaults to 1000, but can
be adjusted in your database config by changing 'statement_limit'.
-* Fix clash between using 'preload' in a default scope and including the default scoped model
- in a nested through association. (GH #2834.) [Jon Leighton]
+* Fix clash between using 'preload', 'joins' or 'eager_load' in a default scope and including the
+ default scoped model in a nested through association. (GH #2834.) [Jon Leighton]
* Ensure we are not comparing a string with a symbol in HasManyAssociation#inverse_updates_counter_cache?.
Fixes GH #2755, where a counter cache could be decremented twice as far as it was supposed to be.
@@ -16,7 +16,7 @@ def target_scope
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
@@ -356,11 +356,13 @@ def test_has_one_through_has_one_through_with_belongs_to_source_reflection
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

0 comments on commit df21e3d

Please sign in to comment.