Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

extract owner id calculation to a method

  • Loading branch information...
commit e7baa6624695d844e903193bcdda1b928bf61042 1 parent b3d6f77
Aaron Patterson tenderlove authored
6 activerecord/lib/active_record/associations/preloader/association.rb
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.