aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-11-05 16:56:41 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-11-05 16:56:50 -0700
commitc43d909ee28484c5e7d7d84b1228e10212d20737 (patch)
treecdfca28b35245121a6deb80b5132d049af5d33c9 /activerecord
parentd89d70236177a074b8357b6104248c86c30c2502 (diff)
downloadrails-c43d909ee28484c5e7d7d84b1228e10212d20737.tar.gz
rails-c43d909ee28484c5e7d7d84b1228e10212d20737.tar.bz2
rails-c43d909ee28484c5e7d7d84b1228e10212d20737.zip
simplify instantiate in the join parts object
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations.rb15
1 files changed, 7 insertions, 8 deletions
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)