diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-10-05 00:58:57 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-10-05 00:58:57 +0900 |
commit | 47adad38166fc6cf6bd306ff0c2f20ea922dbae6 (patch) | |
tree | dfd42f2940b6fc0fcfef600d4e916db461ce8c87 /activerecord/lib/active_record/associations | |
parent | 4429540995b061cf120b6468ce76cbb44fcaba9c (diff) | |
download | rails-47adad38166fc6cf6bd306ff0c2f20ea922dbae6.tar.gz rails-47adad38166fc6cf6bd306ff0c2f20ea922dbae6.tar.bz2 rails-47adad38166fc6cf6bd306ff0c2f20ea922dbae6.zip |
Restore `preloaders_for_one` method
Since the above comment is for the `preloaders_for_one`.
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r-- | activerecord/lib/active_record/associations/preloader.rb | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/associations/preloader.rb b/activerecord/lib/active_record/associations/preloader.rb index 9253f4ccb4..8997579527 100644 --- a/activerecord/lib/active_record/associations/preloader.rb +++ b/activerecord/lib/active_record/associations/preloader.rb @@ -102,10 +102,7 @@ module ActiveRecord when Hash preloaders_for_hash(association, records, scope, polymorphic_parent) when Symbol, String - grouped_records(association.to_sym, records, polymorphic_parent) - .flat_map do |reflection, reflection_records| - preloaders_for_reflection reflection, reflection_records, scope - end + preloaders_for_one(association, records, scope, polymorphic_parent) else raise ArgumentError, "#{association.inspect} was not recognized for preload" end @@ -127,7 +124,7 @@ module ActiveRecord # Loads all the given data into +records+ for a singular +association+. # - # Functions by instantiating a preloader class such as Preloader::HasManyThrough and + # Functions by instantiating a preloader class such as Preloader::Association and # call the +run+ method for each passed in class in the +records+ argument. # # Not all records have the same class, so group then preload group on the reflection @@ -137,6 +134,13 @@ module ActiveRecord # Additionally, polymorphic belongs_to associations can have multiple associated # classes, depending on the polymorphic_type field. So we group by the classes as # well. + def preloaders_for_one(association, records, scope, polymorphic_parent) + grouped_records(association, records, polymorphic_parent) + .flat_map do |reflection, reflection_records| + preloaders_for_reflection reflection, reflection_records, scope + end + end + def preloaders_for_reflection(reflection, records, scope) records.group_by { |record| record.association(reflection.name).klass }.map do |rhs_klass, rs| loader = preloader_for(reflection, rs).new(rhs_klass, rs, reflection, scope) |