From 041ca224c37337ea2a95566207d9ee75015bd99d Mon Sep 17 00:00:00 2001 From: Pavel Balashou Date: Mon, 7 Jul 2025 11:01:32 +0200 Subject: [PATCH] Clarify STI models loading process with a comment. --- config/initializers/sti_eager_load.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/config/initializers/sti_eager_load.rb b/config/initializers/sti_eager_load.rb index ea2da38bc8d..3cdd94b830d 100644 --- a/config/initializers/sti_eager_load.rb +++ b/config/initializers/sti_eager_load.rb @@ -28,16 +28,21 @@ # See COPYRIGHT and LICENSE files for more details. #++ +# Here we are loading STI models explicitly using rails autoloader. +# It is relevant for environments where lazy loading is enabled (usually, development and testing). +# If an STI model has not been loaded it can lead to undesired behavior like: +# Fetching not loaded yet STI model (ServiceAccount) through its parent model(User) +# (e.g. User.find(service_account_id) raises ActiveRecord::NotFound. Rails.application.config.to_prepare do - # Load Enumeration descendants due to STI + # Load Enumeration descendants IssuePriority - # Load Principal descendants due to STI + # Load Principal descendants User PlaceholderUser Group - # Use User descendants due to STI + # Load User descendants SystemUser AnonymousUser Users::InexistentUser