STI workaround for Zeitwerk autoload

Problem to solve

When enabling Zeitwerk with autoload, Sigle Table Inheritance may not work because of the order in which files are loaded. This is a documented problem, and there is a solution on official rails documentation

Proposal

We need to create a module that will load table inheritance the first time it is needed, and we need to require and include that on each root-level model.

https://guides.rubyonrails.org/autoloading_and_reloading_constants.html#single-table-inheritance

With that change in place we don't need to eager_load models anymore.

Additional information

We don't have documented all models that are using STI, but we can probably find those with some RegExp against app/models and ee/app/models

class [a-zA-Z]* \< (?!Base|ActiveRecord|ApplicationRecord|SimpleDelegator).*$
Edited Apr 27, 2020 by Gabriel Mazetto
Assignee Loading
Time tracking Loading