Skip to content

Commit

Permalink
Merge pull request #16867 from Fryguy/fix_descendant_loader_for_non_a…
Browse files Browse the repository at this point in the history
…r_models

Change DescendantLoader to handle non-AR classes in the models directory
(cherry picked from commit d4ce76f)

https://bugzilla.redhat.com/show_bug.cgi?id=1537788
  • Loading branch information
bdunne authored and simaishi committed Jan 23, 2018
1 parent 4e25d98 commit 5ba1310
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/extensions/descendant_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down

0 comments on commit 5ba1310

Please sign in to comment.