diff options
author | Paul Nikitochkin <paul.nikitochkin@gmail.com> | 2013-10-27 19:39:22 +0200 |
---|---|---|
committer | Paul Nikitochkin <paul.nikitochkin@gmail.com> | 2013-10-27 21:15:41 +0200 |
commit | 6b71a1416cb1457517b27cd0a55cb32df0cdf0c3 (patch) | |
tree | 207643bae962d99f0a32973010217837909662fa /activerecord/lib/active_record/associations | |
parent | 52199d1fd41ffc439357c16a7873fb04444175cd (diff) | |
download | rails-6b71a1416cb1457517b27cd0a55cb32df0cdf0c3.tar.gz rails-6b71a1416cb1457517b27cd0a55cb32df0cdf0c3.tar.bz2 rails-6b71a1416cb1457517b27cd0a55cb32df0cdf0c3.zip |
Skip `include_values` from through associations chains for building target scope
Fixes: #12242, #9517, #10240
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r-- | activerecord/lib/active_record/associations/association_scope.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/association_scope.rb b/activerecord/lib/active_record/associations/association_scope.rb index d862a5f29d..17f056e764 100644 --- a/activerecord/lib/active_record/associations/association_scope.rb +++ b/activerecord/lib/active_record/associations/association_scope.rb @@ -78,7 +78,8 @@ module ActiveRecord scope = scope.joins(join(foreign_table, constraint)) end - klass = i == 0 ? self.klass : reflection.klass + is_first_chain = i == 0 + klass = is_first_chain ? self.klass : reflection.klass # Exclude the scope of the association itself, because that # was already merged in the #scope method. @@ -89,7 +90,10 @@ module ActiveRecord scope.merge! item.except(:where, :includes, :bind) end - scope.includes! item.includes_values + if is_first_chain + scope.includes! item.includes_values + end + scope.where_values += item.where_values scope.order_values |= item.order_values end |