Permalink
Browse files

extract owner id calculation to a method

  • Loading branch information...
1 parent b3d6f77 commit e7baa6624695d844e903193bcdda1b928bf61042 @tenderlove tenderlove committed Aug 29, 2013
Showing with 5 additions and 1 deletion.
  1. +5 −1 activerecord/lib/active_record/associations/preloader/association.rb
@@ -87,7 +87,7 @@ def associated_records_by_owner
# Each record may have multiple owners, and vice-versa
records_by_owner = Hash[owners.map { |owner| [owner, []] }]
records.each do |record|
- owner_key = record[association_key_name].to_s
+ owner_key = owner_id_for records, record
owners_map[owner_key].each do |owner|
records_by_owner[owner] << record
@@ -96,6 +96,10 @@ def associated_records_by_owner
records_by_owner
end
+ def owner_id_for(results, record)
+ record[association_key_name].to_s
+ end
+
def reflection_scope
@reflection_scope ||= reflection.scope ? klass.unscoped.instance_exec(nil, &reflection.scope) : klass.unscoped
end

0 comments on commit e7baa66

Please sign in to comment.