1
0
Fork 0
This repository has been archived on 2023-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
lpr-partynest/app/models/org_unit.rb

36 lines
804 B
Ruby
Raw Normal View History

2019-09-30 18:20:45 -04:00
# frozen_string_literal: true
class OrgUnit < ApplicationRecord
################
# Associations #
################
belongs_to :kind,
class_name: 'OrgUnitKind',
inverse_of: :instances
belongs_to :parent,
class_name: 'OrgUnit',
inverse_of: :children,
optional: true
has_many :children,
class_name: 'OrgUnit',
inverse_of: :parent,
foreign_key: :parent_id
###############
# Validations #
###############
2019-09-30 18:32:04 -04:00
validates :short_name, good_small_text: true, uniqueness: true
2019-09-30 18:20:45 -04:00
validates :name, good_small_text: true, uniqueness: true
validates :parent,
presence: {
if: ->(record) { record.kind&.parent_kind },
message: :required,
}
end