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 :name, good_small_text: true, uniqueness: true
|
||||||
|
|
||||||
validates :parent_unit,
|
validates :parent_unit,
|
||||||
presence: {
|
presence: { if: :requires_parent?, message: :required },
|
||||||
if: ->(record) { record.kind&.parent_kind },
|
absence: { unless: :requires_parent? }
|
||||||
message: :required,
|
|
||||||
},
|
|
||||||
absence: {
|
|
||||||
unless: ->(record) {record.kind&.parent_kind },
|
|
||||||
}
|
|
||||||
|
|
||||||
validates :resource,
|
validates :resource,
|
||||||
presence: {
|
presence: {
|
||||||
|
@ -58,6 +53,14 @@ class OrgUnit < ApplicationRecord
|
||||||
|
|
||||||
before_validation :set_level
|
before_validation :set_level
|
||||||
|
|
||||||
|
###########
|
||||||
|
# Methods #
|
||||||
|
###########
|
||||||
|
|
||||||
|
def requires_parent?
|
||||||
|
kind&.parent_kind
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def parent_matches_kind
|
def parent_matches_kind
|
||||||
|
|
Reference in a new issue