aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations.rb
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2016-11-21 12:41:35 +0100
committerYves Senn <yves.senn@gmail.com>2016-11-21 12:41:35 +0100
commitfc4c15d823b112cc440cbd9a4288e1a389c138da (patch)
tree3c8a0a2ca024d959b132914e4e6871d27deb658a /activerecord/lib/active_record/associations.rb
parent6d6249b1c1abda4f62fafcc42a7ece570c8da7e9 (diff)
downloadrails-fc4c15d823b112cc440cbd9a4288e1a389c138da.tar.gz
rails-fc4c15d823b112cc440cbd9a4288e1a389c138da.tar.bz2
rails-fc4c15d823b112cc440cbd9a4288e1a389c138da.zip
`eager_autoload` needs to be triggered for nested constants.
When `ActiveRecord::Associations.eager_load!` is called, it eager loads the `Preloader` but does not trigger a `eager_load!` on the `Preloader` itself. A eager loaded component is responsible to forward the `eager_load!` call to nested constants that make use of `eager_autoload` as well. This will also resolve the occasional `NameError` that we've observed in production: ``` NameError: uninitialized constant ActiveRecord::Associations::Preloader::BelongsTo ```
Diffstat (limited to 'activerecord/lib/active_record/associations.rb')
-rw-r--r--activerecord/lib/active_record/associations.rb5
1 files changed, 5 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 3c94c4bd7f..19308643f3 100644
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -224,6 +224,11 @@ module ActiveRecord
autoload :AliasTracker
end
+ def self.eager_load!
+ super
+ Preloader.eager_load!
+ end
+
# Returns the association instance for the given name, instantiating it if it doesn't already exist
def association(name) #:nodoc:
association = association_instance_get(name)