Allow cascade delete Unit/Quantity

Closes #32
This commit is contained in:
2026-02-22 17:50:43 +01:00
parent 1ba7d29441
commit 80130fb7d1
9 changed files with 19 additions and 17 deletions

View File

@@ -3,7 +3,8 @@ class Unit < ApplicationRecord
belongs_to :user, optional: true
belongs_to :base, optional: true, class_name: "Unit"
has_many :subunits, class_name: "Unit", inverse_of: :base, dependent: :restrict_with_error
has_many :subunits, class_name: "Unit", inverse_of: :base,
dependent: :restrict_with_error
validate if: ->{ base.present? } do
errors.add(:base, :user_mismatch) unless user_id == base.user_id