The Problem Active Record provides STIs to easily work with hierarchies of (persisted) models. They have a few rough edges, however: Active Record needs to know the entire hierarchy to be able to build correct queries. This is at odds with lazy load...
Markdown supported · ⌘↵ to post
To confirm, whilst this idea won't auto discover new subclasses, it will auto-reload changes to any of the STI class files?
Can't we use something like
Rails.autoloaders.main.on_load('MyModel') { ... }?This can be useful when applying the strategy pattern, in the same vein as having a
_stias a suffi, a team can use axxxBasesuffix.Which makes me want to ask you this question: Can we use a regular expression with the
on_loadhook?. This in combination with the_stiprefix idea, we can eager load a directory if it exists.Basically the
Baseclass will act as a router, look through the descendants and return the first applicable strategy class ( like ActiveJob::Serializers does )Do you think this is feasible? Thanks for the article!