From fc4f63200c564f44ab850e1f9895397783f19847 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Wed, 13 Nov 2024 11:09:15 +0200 Subject: [PATCH 1/2] dx: raise informative error when `inverse_of` is missing on STI --- app/controllers/avo/associations_controller.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/controllers/avo/associations_controller.rb b/app/controllers/avo/associations_controller.rb index 7b6a74e6c..82a2f408a 100644 --- a/app/controllers/avo/associations_controller.rb +++ b/app/controllers/avo/associations_controller.rb @@ -117,6 +117,13 @@ def destroy def set_reflection @reflection = @record.class.reflect_on_association(association_from_params) + + # Ensure inverse_of is present on STI + if !@record.class.descends_from_active_record? && @reflection.inverse_of.blank? && Rails.env.development? + raise "Avo relies on the 'inverse_of' option to establish the inverse association and perform some specific logic.\n"\ + "Please configure the 'inverse_of' option for the '#{@reflection.macro} :#{@reflection.name}' association "\ + "in the '#{@reflection.active_record.name}' model." + end end def set_attachment_class From 2b44d0b5cd48fb191543e474019b27f119740c9f Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Wed, 13 Nov 2024 11:18:27 +0200 Subject: [PATCH 2/2] lint --- app/controllers/avo/associations_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/avo/associations_controller.rb b/app/controllers/avo/associations_controller.rb index 82a2f408a..467f09e46 100644 --- a/app/controllers/avo/associations_controller.rb +++ b/app/controllers/avo/associations_controller.rb @@ -120,8 +120,8 @@ def set_reflection # Ensure inverse_of is present on STI if !@record.class.descends_from_active_record? && @reflection.inverse_of.blank? && Rails.env.development? - raise "Avo relies on the 'inverse_of' option to establish the inverse association and perform some specific logic.\n"\ - "Please configure the 'inverse_of' option for the '#{@reflection.macro} :#{@reflection.name}' association "\ + raise "Avo relies on the 'inverse_of' option to establish the inverse association and perform some specific logic.\n" \ + "Please configure the 'inverse_of' option for the '#{@reflection.macro} :#{@reflection.name}' association " \ "in the '#{@reflection.active_record.name}' model." end end