make sure we keep parent records in order

This commit is contained in:
Aaron Patterson 2010-11-06 14:32:41 -07:00
parent 39a8056791
commit c11102d4f8
1 changed files with 6 additions and 6 deletions

View File

@ -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