diff options
author | Sean Griffin <sean@thoughtbot.com> | 2015-01-27 11:04:56 -0700 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2015-01-27 11:04:56 -0700 |
commit | 102a5272c5944a6f715da8332d18e7e0380727d1 (patch) | |
tree | 0a5d0f279050d12c3a46a2864abbb643bbe3832c /activerecord/lib | |
parent | ae299dd45d1fff2775d631e240593d4d3684673e (diff) | |
download | rails-102a5272c5944a6f715da8332d18e7e0380727d1.tar.gz rails-102a5272c5944a6f715da8332d18e7e0380727d1.tar.bz2 rails-102a5272c5944a6f715da8332d18e7e0380727d1.zip |
Don't rely on the internal representation of join values
I'm going to be extracting this logic into a clause class, things need
to go through a method and not access the values hash directly.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/preloader.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/preloader/association.rb | 6 |
2 files changed, 6 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/preloader.rb b/activerecord/lib/active_record/associations/preloader.rb index c3e49007ea..97f4bd3811 100644 --- a/activerecord/lib/active_record/associations/preloader.rb +++ b/activerecord/lib/active_record/associations/preloader.rb @@ -89,7 +89,7 @@ module ActiveRecord # { author: :avatar } # [ :books, { author: :avatar } ] - NULL_RELATION = Struct.new(:values, :where_clause).new({}, Relation::WhereClause.empty) + NULL_RELATION = Struct.new(:values, :where_clause, :joins_values).new({}, Relation::WhereClause.empty, []) def preload(records, associations, preload_scope = nil) records = Array.wrap(records).compact.uniq diff --git a/activerecord/lib/active_record/associations/preloader/association.rb b/activerecord/lib/active_record/associations/preloader/association.rb index 23848f5e54..9e4a2b925c 100644 --- a/activerecord/lib/active_record/associations/preloader/association.rb +++ b/activerecord/lib/active_record/associations/preloader/association.rb @@ -139,7 +139,11 @@ module ActiveRecord scope._select! preload_values[:select] || values[:select] || table[Arel.star] scope.includes! preload_values[:includes] || values[:includes] - scope.joins! preload_values[:joins] || values[:joins] + if preload_scope.joins_values.any? + scope.joins!(preload_scope.joins_values) + else + scope.joins!(reflection_scope.joins_values) + end scope.order! preload_values[:order] || values[:order] if preload_values[:readonly] || values[:readonly] |