Permalink
Browse files

make sure we keep parent records in order

  • Loading branch information...
1 parent 39a8056 commit c11102d4f80267e3774985329ea93e7368e8684f @tenderlove tenderlove committed Nov 6, 2010
Showing with 6 additions and 6 deletions.
  1. +6 −6 activerecord/lib/active_record/associations.rb
@@ -1873,15 +1873,15 @@ def count_aliases_from_table_joins(name)
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

0 comments on commit c11102d

Please sign in to comment.