diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-08-28 17:47:53 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-08-28 17:47:53 -0700 |
commit | e7baa6624695d844e903193bcdda1b928bf61042 (patch) | |
tree | 51585721d8cbbb21e7527ec6aa78669b3e9518fd /activerecord | |
parent | b3d6f77f32072a96e68502b0488bfd6bea1128b4 (diff) | |
download | rails-e7baa6624695d844e903193bcdda1b928bf61042.tar.gz rails-e7baa6624695d844e903193bcdda1b928bf61042.tar.bz2 rails-e7baa6624695d844e903193bcdda1b928bf61042.zip |
extract owner id calculation to a method
Diffstat (limited to 'activerecord')
-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 |