diff options
author | Jon Leighton <j@jonathanleighton.com> | 2010-12-12 16:35:27 +0000 |
---|---|---|
committer | Vijay Dev <vijaydev.cse@gmail.com> | 2010-12-16 01:49:30 +0530 |
commit | eba76640862d071d89c846f8624d1e651d872794 (patch) | |
tree | be04cbd5426cb1be276b1e25335f83aa77f18762 /activerecord/lib/active_record | |
parent | ebc47465a5865ab91dc7d058d2d8a0cc961510d7 (diff) | |
download | rails-eba76640862d071d89c846f8624d1e651d872794.tar.gz rails-eba76640862d071d89c846f8624d1e651d872794.tar.bz2 rails-eba76640862d071d89c846f8624d1e651d872794.zip |
Respect the default_scope on a join model when reading a through association
Diffstat (limited to 'activerecord/lib/active_record')
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 |