From fc4c15d823b112cc440cbd9a4288e1a389c138da Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Mon, 21 Nov 2016 12:41:35 +0100 Subject: `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 ``` --- activerecord/lib/active_record/associations.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activerecord/lib') 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) -- cgit v1.2.3