diff options
author | Jan Habermann <jan@habermann24.com> | 2014-04-03 01:52:42 +0200 |
---|---|---|
committer | Jan Habermann <jan@habermann24.com> | 2014-04-03 01:52:42 +0200 |
commit | 98e69078d5e2fe9a13bd912bbb5da00be4d43497 (patch) | |
tree | d4da280a5a00d4ace96a3dab58bc5fbe14b93b5e /activerecord/lib | |
parent | 165d93b22ff5f8798296bd5d7642d0ddb8996c74 (diff) | |
download | rails-98e69078d5e2fe9a13bd912bbb5da00be4d43497.tar.gz rails-98e69078d5e2fe9a13bd912bbb5da00be4d43497.tar.bz2 rails-98e69078d5e2fe9a13bd912bbb5da00be4d43497.zip |
Properly handle scoping with has_many :through. Fixes #14537.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/through_association.rb | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/through_association.rb b/activerecord/lib/active_record/associations/through_association.rb index ba7d2a3782..66b1616949 100644 --- a/activerecord/lib/active_record/associations/through_association.rb +++ b/activerecord/lib/active_record/associations/through_association.rb @@ -14,9 +14,14 @@ module ActiveRecord def target_scope scope = super chain.drop(1).each do |reflection| + relation = if reflection.scope + reflection.klass.all.instance_eval(&reflection.scope) + else + reflection.klass.all + end + scope.merge!( - reflection.klass.all. - except(:select, :create_with, :includes, :preload, :joins, :eager_load) + relation.except(:select, :create_with, :includes, :preload, :joins, :eager_load) ) end scope |