aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-12-26 20:22:13 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-12-26 20:22:13 -0700
commit9bac649fa4ca6f05795e7cab8d30049aa2410cb8 (patch)
tree2006ac7938dfe30af821e515d8798e52dfbf1356 /activerecord/lib/active_record
parent67da59097909295c59574e3fd3b502022f860aea (diff)
downloadrails-9bac649fa4ca6f05795e7cab8d30049aa2410cb8.tar.gz
rails-9bac649fa4ca6f05795e7cab8d30049aa2410cb8.tar.bz2
rails-9bac649fa4ca6f05795e7cab8d30049aa2410cb8.zip
try not to make so many funcalls
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/association_preload.rb9
1 files changed, 6 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/association_preload.rb b/activerecord/lib/active_record/association_preload.rb
index b39b703a92..ecf7b6c210 100644
--- a/activerecord/lib/active_record/association_preload.rb
+++ b/activerecord/lib/active_record/association_preload.rb
@@ -147,13 +147,16 @@ module ActiveRecord
def set_association_single_records(id_to_record_map, reflection_name, associated_records, key)
seen_keys = {}
associated_records.each do |associated_record|
+ seen_key = associated_record[key].to_s
+
#this is a has_one or belongs_to: there should only be one record.
#Unfortunately we can't (in portable way) ask the database for
#'all records where foo_id in (x,y,z), but please
# only one row per distinct foo_id' so this where we enforce that
- next if seen_keys[associated_record[key].to_s]
- seen_keys[associated_record[key].to_s] = true
- mapped_records = id_to_record_map[associated_record[key].to_s]
+ next if seen_keys.key? seen_key
+
+ seen_keys[seen_key] = true
+ mapped_records = id_to_record_map[seen_key]
mapped_records.each do |mapped_record|
association_proxy = mapped_record.send("set_#{reflection_name}_target", associated_record)
association_proxy.send(:set_inverse_instance, associated_record)