diff --git a/app/models/quantity.rb b/app/models/quantity.rb index 2d232f7..3dedc3f 100644 --- a/app/models/quantity.rb +++ b/app/models/quantity.rb @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index 439c164..d0efc19 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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'