diff --git a/lib/extensions/descendant_loader.rb b/lib/extensions/descendant_loader.rb index 1d6d42df0fa..c9b99dd4cce 100644 --- a/lib/extensions/descendant_loader.rb +++ b/lib/extensions/descendant_loader.rb @@ -267,9 +267,11 @@ def clear end end -ActiveRecord::Base.singleton_class.send(:prepend, DescendantLoader::ArDescendantsWithLoader) -ActiveSupport::Dependencies.send(:prepend, DescendantLoader::AsDependenciesClearWithLoader) -ActsAsArModel.singleton_class.send(:prepend, DescendantLoader::ArDescendantsWithLoader) +# Patch Class to support non-AR models in the models directory +Class.prepend(DescendantLoader::ArDescendantsWithLoader) +# Patch ActiveRecord specifically to get ahead of ActiveSupport::DescendantsTracker +# The patching of Class does not put it in the right place in the ancestors chain +ActiveRecord::Base.singleton_class.prepend(DescendantLoader::ArDescendantsWithLoader) at_exit do DescendantLoader.instance.save_cache!