Make Quantity name unique among siblings

Remove Quantity domain - will be replaced by configurable per-domain
root Quantity, limiting selection to descendants only
This commit is contained in:
2025-01-11 21:50:36 +01:00
parent 57f10c94a4
commit b6acb30785
3 changed files with 4 additions and 3 deletions

View File

@@ -9,7 +9,8 @@ class Quantity < ApplicationRecord
validate if: ->{ parent.present? } do
errors.add(:parent, :user_mismatch) unless user == parent.user
end
validates :name, presence: true, length: {maximum: type_for_attribute(:name).limit}
validates :name, presence: true, uniqueness: {scope: [:user_id, :parent_id]},
length: {maximum: type_for_attribute(:name).limit}
validates :description, length: {maximum: type_for_attribute(:description).limit}
scope :defaults, ->{ where(user: nil) }