aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/association_preload.rb
diff options
context:
space:
mode:
authorGrant Ammons <grant@pipelinedealsco.com>2010-06-28 16:37:38 -0400
committerJosé Valim <jose.valim@gmail.com>2010-07-08 22:36:26 +0200
commit17650e394fae26984d506fd0f705bc32e5a5de27 (patch)
tree10f2628b9b4db4a4a0df3dc8c5f061d2aac5d8e1 /activerecord/lib/active_record/association_preload.rb
parente848ab527ca9da1a6cf2a8485163f01daf3f66d1 (diff)
downloadrails-17650e394fae26984d506fd0f705bc32e5a5de27.tar.gz
rails-17650e394fae26984d506fd0f705bc32e5a5de27.tar.bz2
rails-17650e394fae26984d506fd0f705bc32e5a5de27.zip
Eager loading :through associations will join the :source model if there are :conditions. [#2362 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activerecord/lib/active_record/association_preload.rb')
-rw-r--r--activerecord/lib/active_record/association_preload.rb7
1 files changed, 6 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/association_preload.rb b/activerecord/lib/active_record/association_preload.rb
index f13c250ca4..cbec5789fd 100644
--- a/activerecord/lib/active_record/association_preload.rb
+++ b/activerecord/lib/active_record/association_preload.rb
@@ -282,7 +282,12 @@ module ActiveRecord
end
end
else
- records.first.class.preload_associations(records, through_association)
+ options = {}
+ options[:include] = reflection.options[:include] || reflection.options[:source] if reflection.options[:conditions]
+ options[:order] = reflection.options[:order]
+ options[:conditions] = reflection.options[:conditions]
+ records.first.class.preload_associations(records, through_association, options)
+
records.each do |record|
through_records.concat Array.wrap(record.send(through_association))
end