diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-12-25 16:47:59 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-12-25 16:47:59 -0700 |
commit | d767252d72063af053fdf1391461704a1a5e1f4a (patch) | |
tree | 7f9772ae9e78db8de14e4828661e39893d1ead57 /activerecord | |
parent | bde643fbec7d1b80309d3387635f4a2e9dadccc2 (diff) | |
download | rails-d767252d72063af053fdf1391461704a1a5e1f4a.tar.gz rails-d767252d72063af053fdf1391461704a1a5e1f4a.tar.bz2 rails-d767252d72063af053fdf1391461704a1a5e1f4a.zip |
refactor to use group_by
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/association_preload.rb | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/association_preload.rb b/activerecord/lib/active_record/association_preload.rb index a305551093..ba225b700c 100644 --- a/activerecord/lib/active_record/association_preload.rb +++ b/activerecord/lib/active_record/association_preload.rb @@ -336,11 +336,11 @@ module ActiveRecord end end else - id_map = {} - records.each do |record| + id_map = records.group_by do |record| key = record.send(primary_key_name) - (id_map[key.to_s] ||= []) << record if key + key && key.to_s end + id_map.delete nil klasses_and_ids[reflection.klass.name] = id_map unless id_map.empty? end |