diff options
author | Jon Leighton <j@jonathanleighton.com> | 2010-12-12 16:35:27 +0000 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-12-15 11:03:58 -0800 |
commit | 16e93f2c3c3ca37d2bae9801b680b05f75c48c18 (patch) | |
tree | 366a5c1fa37914140a81175aa545b8f9d0ec228e /activerecord/lib | |
parent | 439c23dce33148064c258eaf6e79f9d4563c88a4 (diff) | |
download | rails-16e93f2c3c3ca37d2bae9801b680b05f75c48c18.tar.gz rails-16e93f2c3c3ca37d2bae9801b680b05f75c48c18.tar.bz2 rails-16e93f2c3c3ca37d2bae9801b680b05f75c48c18.zip |
Respect the default_scope on a join model when reading a through association
Diffstat (limited to 'activerecord/lib')
3 files changed, 9 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb index 6ad51e2fb4..781aa7ef62 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -81,7 +81,7 @@ module ActiveRecord def find_target return [] unless target_reflection_has_associated_record? - with_scope(@scope) { @reflection.klass.find(:all) } + scoped.all end def has_cached_counter? diff --git a/activerecord/lib/active_record/associations/has_one_through_association.rb b/activerecord/lib/active_record/associations/has_one_through_association.rb index 7f28abf464..e8cf73976b 100644 --- a/activerecord/lib/active_record/associations/has_one_through_association.rb +++ b/activerecord/lib/active_record/associations/has_one_through_association.rb @@ -33,7 +33,7 @@ module ActiveRecord private def find_target - with_scope(@scope) { @reflection.klass.find(:first) } + scoped.first end end end diff --git a/activerecord/lib/active_record/associations/through_association_scope.rb b/activerecord/lib/active_record/associations/through_association_scope.rb index a55bf6323e..2ecd0f054a 100644 --- a/activerecord/lib/active_record/associations/through_association_scope.rb +++ b/activerecord/lib/active_record/associations/through_association_scope.rb @@ -3,6 +3,13 @@ module ActiveRecord module Associations module ThroughAssociationScope + def scoped + with_scope(@scope) do + @reflection.klass.scoped & + @reflection.through_reflection.klass.scoped + end + end + protected def construct_find_scope |