1
0
Fork 0

Validate OrgUnit#parent

This commit is contained in:
Alex Kotov 2019-10-01 04:32:04 +05:00
parent 30c5bf90d1
commit 36a7d02c20
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08

View file

@ -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