1
0

Validating parent quantity domain

This commit is contained in:
cryptogopher 2019-09-08 21:10:25 +02:00
parent b31ab9d16a
commit a96cd717cf
2 changed files with 11 additions and 0 deletions

View File

@ -12,4 +12,8 @@ class Quantity < ActiveRecord::Base
validates :project, associated: true
validates :name, presence: true, uniqueness: {scope: :project_id}
validates :domain, inclusion: {in: domains.keys}
validates :parent, associated: true
validate if: -> { parent.present? } do
errors.add(:parent, :parent_domain_mismatch) unless domain == parent.domain
end
end

View File

@ -5,6 +5,13 @@ en:
field_action: 'Action'
field_domain: 'Domain'
field_parent_quantity: 'Parent'
activerecord:
errors:
models:
quantity:
attributes:
parent:
parent_domain_mismatch: 'parent quantity has to be in the same domain'
body_trackers:
index:
heading: 'Summary'