diff options
-rw-r--r-- | activerecord/lib/active_record/associations/association_scope.rb | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/associations/association_scope.rb b/activerecord/lib/active_record/associations/association_scope.rb index 4907d1cf6c..b5a6954554 100644 --- a/activerecord/lib/active_record/associations/association_scope.rb +++ b/activerecord/lib/active_record/associations/association_scope.rb @@ -187,21 +187,16 @@ module ActiveRecord scope = next_chain_scope(scope, table, reflection, connection, assoc_klass, foreign_table, next_reflection) end - is_first_chain = i == 0 - klass = is_first_chain ? assoc_klass : reflection.klass - - items = reflection.constraints - # Exclude the scope of the association itself, because that # was already merged in the #scope method. - items.each do |scope_chain_item| - item = eval_scope(klass, scope_chain_item, owner) + reflection.constraints.each do |scope_chain_item| + item = eval_scope(reflection.klass, scope_chain_item, owner) if scope_chain_item == refl.scope scope.merge! item.except(:where, :includes, :bind) end - if is_first_chain + if i == 0 scope.includes! item.includes_values end |