aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2017-06-27 12:22:46 -0400
committerGitHub <noreply@github.com>2017-06-27 12:22:46 -0400
commitadea9413665ce7885f1c408b21616c72f768c509 (patch)
tree33b0696efb420d3c07ba3e790901ddbc19fce2df /activerecord/lib
parent61cc630ac7e7f8554dc049a3e5a2509c00303ef8 (diff)
parent0496b7b3b2f38cba8b6fc7fbbff70a0bb5e4bc43 (diff)
downloadrails-adea9413665ce7885f1c408b21616c72f768c509.tar.gz
rails-adea9413665ce7885f1c408b21616c72f768c509.tar.bz2
rails-adea9413665ce7885f1c408b21616c72f768c509.zip
Merge pull request #29587 from kamipo/skip_instantiating_null_preloader
Skip instantiating `NullPreloader` if `assoc.klass` is nil
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/preloader.rb14
1 files changed, 3 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/associations/preloader.rb b/activerecord/lib/active_record/associations/preloader.rb
index 9f77f38b35..208d1b2670 100644
--- a/activerecord/lib/active_record/associations/preloader.rb
+++ b/activerecord/lib/active_record/associations/preloader.rb
@@ -147,7 +147,7 @@ module ActiveRecord
def preloaders_for_one(association, records, scope)
grouped_records(association, records).flat_map do |reflection, klasses|
klasses.map do |rhs_klass, rs|
- loader = preloader_for(reflection, rs, rhs_klass).new(rhs_klass, rs, reflection, scope)
+ loader = preloader_for(reflection, rs).new(rhs_klass, rs, reflection, scope)
loader.run self
loader
end
@@ -159,6 +159,7 @@ module ActiveRecord
records.each do |record|
next unless record
assoc = record.association(association)
+ next unless assoc.klass
klasses = h[assoc.reflection] ||= {}
(klasses[assoc.klass] ||= []) << record
end
@@ -180,20 +181,11 @@ module ActiveRecord
end
end
- class NullPreloader # :nodoc:
- def self.new(klass, owners, reflection, preload_scope); self; end
- def self.run(preloader); end
- def self.preloaded_records; []; end
- def self.owners; []; end
- end
-
# Returns a class containing the logic needed to load preload the data
# and attach it to a relation. For example +Preloader::Association+ or
# +Preloader::HasManyThrough+. The class returned implements a `run` method
# that accepts a preloader.
- def preloader_for(reflection, owners, rhs_klass)
- return NullPreloader unless rhs_klass
-
+ def preloader_for(reflection, owners)
if owners.first.association(reflection.name).loaded?
return AlreadyLoaded
end