Validate OrgUnit#parent
This commit is contained in:
parent
30c5bf90d1
commit
36a7d02c20
1 changed files with 8 additions and 0 deletions
|
@ -32,4 +32,12 @@ class OrgUnit < ApplicationRecord
|
|||
if: ->(record) { record.kind&.parent_kind },
|
||||
message: :required,
|
||||
}
|
||||
|
||||
validate :parent_matches_kind
|
||||
|
||||
private
|
||||
|
||||
def parent_matches_kind
|
||||
errors.add :parent unless parent&.kind == kind&.parent_kind
|
||||
end
|
||||
end
|
||||
|
|
Reference in a new issue