From 5ba1310826e1bb842403102665ff3f71ea5c9898 Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Tue, 23 Jan 2018 10:49:13 -0500 Subject: [PATCH] Merge pull request #16867 from Fryguy/fix_descendant_loader_for_non_ar_models Change DescendantLoader to handle non-AR classes in the models directory (cherry picked from commit d4ce76fc5ed334e1261089ad7f8a7ac7033b5bde) https://bugzilla.redhat.com/show_bug.cgi?id=1537788 --- lib/extensions/descendant_loader.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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!