aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/preloader/through_association.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-05-18 10:42:26 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-07-04 07:28:44 +0900
commit2bfa2c02a891d4817832807343c6f1d56e9bae50 (patch)
tree4e9d767231cb3adf0518368875b81a1b57ae8428 /activerecord/lib/active_record/associations/preloader/through_association.rb
parent4aa76ed38a8609ad713e2b39ccb1fa97c5c64682 (diff)
downloadrails-2bfa2c02a891d4817832807343c6f1d56e9bae50.tar.gz
rails-2bfa2c02a891d4817832807343c6f1d56e9bae50.tar.bz2
rails-2bfa2c02a891d4817832807343c6f1d56e9bae50.zip
Fix preloading association with scope including joins
Diffstat (limited to 'activerecord/lib/active_record/associations/preloader/through_association.rb')
-rw-r--r--activerecord/lib/active_record/associations/preloader/through_association.rb13
1 files changed, 10 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/associations/preloader/through_association.rb b/activerecord/lib/active_record/associations/preloader/through_association.rb
index 34587fd3f5..0999746cd5 100644
--- a/activerecord/lib/active_record/associations/preloader/through_association.rb
+++ b/activerecord/lib/active_record/associations/preloader/through_association.rb
@@ -79,17 +79,24 @@ module ActiveRecord
def through_scope
scope = through_reflection.klass.unscoped
+ values = reflection_scope.values
if options[:source_type]
scope.where! reflection.foreign_type => options[:source_type]
else
unless reflection_scope.where_clause.empty?
- scope.includes_values = Array(reflection_scope.values[:includes] || options[:source])
+ scope.includes_values = Array(values[:includes] || options[:source])
scope.where_clause = reflection_scope.where_clause
+ if joins = values[:joins]
+ scope.joins!(source_reflection.name => joins)
+ end
+ if left_outer_joins = values[:left_outer_joins]
+ scope.left_outer_joins!(source_reflection.name => left_outer_joins)
+ end
end
- scope.references! reflection_scope.values[:references]
- if scope.eager_loading? && order_values = reflection_scope.values[:order]
+ scope.references! values[:references]
+ if scope.eager_loading? && order_values = values[:order]
scope = scope.order(order_values)
end
end