diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-02-23 00:17:01 +0000 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-02-28 22:12:34 +0000 |
commit | d90b4e2615e8048fdeffc6dffe3246704adee01f (patch) | |
tree | a17aeea81d5070a55de874fa6617f7212429ae1f /activerecord/lib/active_record/associations/preloader/collection_association.rb | |
parent | 7112cf5e021d8da7c4e073a4e2d2a4afb10671ec (diff) | |
download | rails-d90b4e2615e8048fdeffc6dffe3246704adee01f.tar.gz rails-d90b4e2615e8048fdeffc6dffe3246704adee01f.tar.bz2 rails-d90b4e2615e8048fdeffc6dffe3246704adee01f.zip |
Rewrote AssociationPreload.
Diffstat (limited to 'activerecord/lib/active_record/associations/preloader/collection_association.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/preloader/collection_association.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/preloader/collection_association.rb b/activerecord/lib/active_record/associations/preloader/collection_association.rb new file mode 100644 index 0000000000..c248aeaaf6 --- /dev/null +++ b/activerecord/lib/active_record/associations/preloader/collection_association.rb @@ -0,0 +1,24 @@ +module ActiveRecord + module Associations + class Preloader + class CollectionAssociation < Association #:nodoc: + + private + + def build_scope + super.order(preload_options[:order] || options[:order]) + end + + def preload + associated_records_by_owner.each do |owner, records| + association = owner.association(reflection.name) + association.loaded! + association.target.concat(records) + records.each { |record| association.set_inverse_instance(record) } + end + end + + end + end + end +end |