Add method OrgUnit#requires_parent?
This commit is contained in:
parent
5da3660fa9
commit
7d54eb3192
1 changed files with 10 additions and 7 deletions
|
@ -36,13 +36,8 @@ class OrgUnit < ApplicationRecord
|
|||
validates :name, good_small_text: true, uniqueness: true
|
||||
|
||||
validates :parent_unit,
|
||||
presence: {
|
||||
if: ->(record) { record.kind&.parent_kind },
|
||||
message: :required,
|
||||
},
|
||||
absence: {
|
||||
unless: ->(record) {record.kind&.parent_kind },
|
||||
}
|
||||
presence: { if: :requires_parent?, message: :required },
|
||||
absence: { unless: :requires_parent? }
|
||||
|
||||
validates :resource,
|
||||
presence: {
|
||||
|
@ -58,6 +53,14 @@ class OrgUnit < ApplicationRecord
|
|||
|
||||
before_validation :set_level
|
||||
|
||||
###########
|
||||
# Methods #
|
||||
###########
|
||||
|
||||
def requires_parent?
|
||||
kind&.parent_kind
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def parent_matches_kind
|
||||
|
|
Reference in a new issue