Skip to content

Commit

Permalink
dx: raise informative error when inverse_of is missing on STI (#3414)
Browse files Browse the repository at this point in the history
* dx: raise informative error when `inverse_of` is missing on STI

* lint
  • Loading branch information
Paul-Bob authored Nov 18, 2024
1 parent 6ab8ebe commit f27665a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/controllers/avo/associations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f27665a

Please sign in to comment.