aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations.rb12
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