From c43d909ee28484c5e7d7d84b1228e10212d20737 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 5 Nov 2010 16:56:41 -0700 Subject: simplify instantiate in the join parts object --- activerecord/lib/active_record/associations.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 680810f031..0fc8740dce 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1839,8 +1839,6 @@ module ActiveRecord @join_parts = [JoinBase.new(base, joins)] @associations = {} @reflections = [] - @base_records_hash = {} - @base_records_in_order = [] @table_aliases = Hash.new(0) @table_aliases[base.table_name] = 1 build(associations) @@ -1875,16 +1873,17 @@ module ActiveRecord def instantiate(rows) primary_key = join_base.aliased_primary_key + base_records_hash = {} rows.each do |model| primary_id = model[primary_key] - unless @base_records_hash[primary_id] - @base_records_in_order << (@base_records_hash[primary_id] = join_base.instantiate(model)) - end - construct(@base_records_hash[primary_id], @associations, join_associations.dup, model) + base_records_hash[primary_id] ||= join_base.instantiate(model) + construct(base_records_hash[primary_id], @associations, join_associations.dup, model) end - remove_duplicate_results!(join_base.active_record, @base_records_in_order, @associations) - return @base_records_in_order + + records = base_records_hash.values + remove_duplicate_results!(join_base.active_record, records, @associations) + records end def remove_duplicate_results!(base, records, associations) -- cgit v1.2.3