aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRafael Mendonça França <rafael.franca@plataformatec.com.br>2014-04-22 17:20:52 -0500
committerRafael Mendonça França <rafael.franca@plataformatec.com.br>2014-04-22 17:20:52 -0500
commitc26a690b9964d90eea33f33a513ae9c349678cc0 (patch)
tree202768bd10efa7f1ad8395f324ba0e95f2b6ffc0 /activerecord/lib
parent148d909380cf9b85a51875a6790a6d69a2d0d693 (diff)
parent47a04b8bbf35238639b00bfab500a84607d8d871 (diff)
downloadrails-c26a690b9964d90eea33f33a513ae9c349678cc0.tar.gz
rails-c26a690b9964d90eea33f33a513ae9c349678cc0.tar.bz2
rails-c26a690b9964d90eea33f33a513ae9c349678cc0.zip
Merge pull request #14573 from habermann24/has_many_through_fix
Properly handle scoping with has_many :through. Fixes #14537. Conflicts: activerecord/CHANGELOG.md activerecord/test/cases/associations/has_many_through_associations_test.rb
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/through_association.rb6
1 files changed, 4 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..f8a85b8a6f 100644
--- a/activerecord/lib/active_record/associations/through_association.rb
+++ b/activerecord/lib/active_record/associations/through_association.rb
@@ -14,9 +14,11 @@ module ActiveRecord
def target_scope
scope = super
chain.drop(1).each do |reflection|
+ relation = reflection.klass.all
+ relation.merge!(reflection.scope) if reflection.scope
+
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