lib/kithe/sti_preload.rb in kithe-2.6.1 vs lib/kithe/sti_preload.rb in kithe-2.7.0
- old
+ new
@@ -6,22 +6,30 @@
# fine under Rails 5.2 and previous also, to make sure all sub-classes in
# db are loaded, so ActiveRecord knows how to create SQL WHERE clauses
# on particular inheritance hieararchies.
#
# We include in our Kithe::Model, which uses Single-Table Inheritance
+ #
+ # BUT NOTE: What's in Rails Guide right now actually breaks in Rails 7.
+ #
+ # We've messed with based on https://github.com/rails/rails/issues/45307 et al.
+ #
module StiPreload
- unless Rails.application.config.eager_load
+ unless Rails.configuration.cache_classes && Rails.configuration.eager_load
extend ActiveSupport::Concern
included do
cattr_accessor :preloaded, instance_accessor: false
end
class_methods do
- def descendants
- preload_sti unless preloaded
- super
- end
+
+ # For Rails 7, this now breaks; we work around with an after_initialize hook
+ # in ./kithe/engine.rb . See more links there.
+ # def descendants
+ # preload_sti unless preloaded
+ # super
+ # end
# Constantizes all types present in the database. There might be more on
# disk, but that does not matter in practice as far as the STI API is
# concerned.
#