From a79e1de90a6062926a8ec11870702923eb691944 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 5 Nov 2010 16:27:39 -0700 Subject: reduce method calls to the join base object --- activerecord/lib/active_record/associations.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'activerecord/lib/active_record/associations.rb') diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index dc466eafc2..3d754af5b3 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1874,12 +1874,14 @@ module ActiveRecord end def instantiate(rows) - rows.each_with_index do |row, i| - primary_id = join_base.record_id(row) + primary_key = join_base.aliased_primary_key + + rows.each_with_index do |model, i| + primary_id = model[primary_key] unless @base_records_hash[primary_id] - @base_records_in_order << (@base_records_hash[primary_id] = join_base.instantiate(row)) + @base_records_in_order << (@base_records_hash[primary_id] = join_base.instantiate(model)) end - construct(@base_records_hash[primary_id], @associations, join_associations.dup, row) + 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 -- cgit v1.2.3