aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-01-18 15:05:18 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-01-18 15:52:57 -0800
commit4bc9bacd9458af9f9ad3a5075de6425e3c1c6a1e (patch)
tree769185a9531820bf122290ab243cb507a0769047 /activerecord/lib/active_record
parent36d66786905b3cc2dda6c48345a89bbd760fcb82 (diff)
downloadrails-4bc9bacd9458af9f9ad3a5075de6425e3c1c6a1e.tar.gz
rails-4bc9bacd9458af9f9ad3a5075de6425e3c1c6a1e.tar.bz2
rails-4bc9bacd9458af9f9ad3a5075de6425e3c1c6a1e.zip
refactor elaborate group_by in to a normal group_by
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/association_preload.rb11
1 files changed, 3 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/association_preload.rb b/activerecord/lib/active_record/association_preload.rb
index 68aaff175a..4b90845244 100644
--- a/activerecord/lib/active_record/association_preload.rb
+++ b/activerecord/lib/active_record/association_preload.rb
@@ -177,16 +177,11 @@ 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 = {}
- ids = []
- records.each do |record|
+ id_to_record_map = records.group_by do |record|
primary_key ||= record.class.primary_key
- ids << record[primary_key]
- mapped_records = (id_to_record_map[ids.last.to_s] ||= [])
- mapped_records << record
+ record[primary_key].to_s
end
- ids.uniq!
- return id_to_record_map, ids
+ return id_to_record_map, id_to_record_map.keys
end
def preload_has_and_belongs_to_many_association(records, reflection, preload_options={})