aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-01-18 15:15:20 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-01-18 15:52:57 -0800
commitba62a87b8b3ab2cffb6e8af6c110ec17b9c0bab2 (patch)
treef760c4d5eb915aea137427452038aa915d4a5a02 /activerecord/lib/active_record
parent4bc9bacd9458af9f9ad3a5075de6425e3c1c6a1e (diff)
downloadrails-ba62a87b8b3ab2cffb6e8af6c110ec17b9c0bab2.tar.gz
rails-ba62a87b8b3ab2cffb6e8af6c110ec17b9c0bab2.tar.bz2
rails-ba62a87b8b3ab2cffb6e8af6c110ec17b9c0bab2.zip
ony bother with record map keys when we need them
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/association_preload.rb18
1 files changed, 9 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/association_preload.rb b/activerecord/lib/active_record/association_preload.rb
index 4b90845244..d89f87dbc7 100644
--- a/activerecord/lib/active_record/association_preload.rb
+++ b/activerecord/lib/active_record/association_preload.rb
@@ -177,18 +177,18 @@ module ActiveRecord
# <tt>(id_to_record_map, ids)</tt> where +id_to_record_map+ is the Hash,
# and +ids+ is an Array of record IDs.
def construct_id_map(records, primary_key=nil)
- id_to_record_map = records.group_by do |record|
+ records.group_by do |record|
primary_key ||= record.class.primary_key
record[primary_key].to_s
end
- return id_to_record_map, id_to_record_map.keys
end
def preload_has_and_belongs_to_many_association(records, reflection, preload_options={})
left = reflection.klass.arel_table
- id_to_record_map, ids = construct_id_map(records)
+ id_to_record_map = construct_id_map(records)
+
records.each {|record| record.send(reflection.name).loaded}
options = reflection.options
@@ -217,7 +217,7 @@ module ActiveRecord
klass = associated_records_proxy.klass
- associated_records(ids) { |some_ids|
+ associated_records(id_to_record_map.keys) { |some_ids|
method = in_or_equal(some_ids)
conditions = right[reflection.foreign_key].send(*method)
conditions = custom_conditions.inject(conditions) do |ast, cond|
@@ -237,7 +237,7 @@ module ActiveRecord
def preload_has_one_association(records, reflection, preload_options={})
return if records.first.send(:association_proxy, reflection.name).loaded?
- id_to_record_map, ids = construct_id_map(records, reflection.options[:primary_key])
+ id_to_record_map = construct_id_map(records, reflection.options[:primary_key])
options = reflection.options
records.each do |record|
@@ -253,7 +253,7 @@ module ActiveRecord
source = reflection.source_reflection.name
through_records.first.class.preload_associations(through_records, source)
if through_reflection.macro == :belongs_to
- id_to_record_map = construct_id_map(records, through_primary_key).first
+ id_to_record_map = construct_id_map(records, through_primary_key)
through_primary_key = through_reflection.klass.primary_key
end
@@ -263,7 +263,7 @@ module ActiveRecord
end
end
else
- set_association_single_records(id_to_record_map, reflection.name, find_associated_records(ids, reflection, preload_options), reflection.foreign_key)
+ set_association_single_records(id_to_record_map, reflection.name, find_associated_records(id_to_record_map.keys, reflection, preload_options), reflection.foreign_key)
end
end
@@ -272,7 +272,7 @@ module ActiveRecord
options = reflection.options
foreign_key = reflection.through_reflection_foreign_key
- id_to_record_map, ids = construct_id_map(records, foreign_key || reflection.options[:primary_key])
+ id_to_record_map = construct_id_map(records, foreign_key || reflection.options[:primary_key])
records.each {|record| record.send(reflection.name).loaded}
if options[:through]
@@ -288,7 +288,7 @@ module ActiveRecord
end
else
- set_association_collection_records(id_to_record_map, reflection.name, find_associated_records(ids, reflection, preload_options),
+ set_association_collection_records(id_to_record_map, reflection.name, find_associated_records(id_to_record_map.keys, reflection, preload_options),
reflection.foreign_key)
end
end