From f27665ad18a34be5f1436239ac30ef0b63f56782 Mon Sep 17 00:00:00 2001 From: Paul Bob <69730720+Paul-Bob@users.noreply.github.com> Date: Mon, 18 Nov 2024 10:29:09 +0200 Subject: [PATCH] dx: raise informative error when `inverse_of` is missing on STI (#3414) * dx: raise informative error when `inverse_of` is missing on STI * lint --- 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..467f09e46 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