diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-11-06 14:32:41 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-11-06 14:32:41 -0700 |
commit | c11102d4f80267e3774985329ea93e7368e8684f (patch) | |
tree | 0b1d0ab22bb3266502d8789a0c0efb62f70f237e /activerecord/lib/active_record | |
parent | 39a80567918af298b39898d78062e7a8fb5da601 (diff) | |
download | rails-c11102d4f80267e3774985329ea93e7368e8684f.tar.gz rails-c11102d4f80267e3774985329ea93e7368e8684f.tar.bz2 rails-c11102d4f80267e3774985329ea93e7368e8684f.zip |
make sure we keep parent records in order
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/associations.rb | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 8d415cdfdf..aad0cbb895 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1873,15 +1873,15 @@ module ActiveRecord def instantiate(rows) primary_key = join_base.aliased_primary_key - base_records_hash = {} + parents = {} - rows.each do |model| + records = rows.map { |model| primary_id = model[primary_key] - base_records_hash[primary_id] ||= join_base.instantiate(model) - construct(base_records_hash[primary_id], @associations, join_associations.dup, model) - end + parent = parents[primary_id] ||= join_base.instantiate(model) + construct(parent, @associations, join_associations.dup, model) + parent + }.uniq - records = base_records_hash.values remove_duplicate_results!(join_base.active_record, records, @associations) records end |