`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
```
This commit is contained in:
Yves Senn 2016-11-21 12:41:35 +01:00
parent 6d6249b1c1
commit fc4c15d823
1 changed files with 5 additions and 0 deletions

View File

@ -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)