diff options
-rw-r--r-- | activerecord/lib/active_record/associations/preloader/association.rb | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/preloader/association.rb b/activerecord/lib/active_record/associations/preloader/association.rb index 59aeb4eb6a..39a1d022a4 100644 --- a/activerecord/lib/active_record/associations/preloader/association.rb +++ b/activerecord/lib/active_record/associations/preloader/association.rb @@ -87,7 +87,7 @@ module ActiveRecord # 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 @@ module ActiveRecord 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 |