23 lines
1009 B
Ruby
23 lines
1009 B
Ruby
# frozen_string_literal: true
|
|
|
|
class CharacterSheetSection < ApplicationRecord
|
|
belongs_to :character
|
|
belongs_to :parent_section, optional: true,
|
|
class_name: "CharacterSheetSection"
|
|
has_many :character_sheet_subsections, class_name: "CharacterSheetSection",
|
|
foreign_key: :parent_section_id,
|
|
dependent: :destroy
|
|
has_many :character_sheet_features
|
|
has_many :counters, dependent: :destroy, through: :character_sheet_features,
|
|
source: :featurable, source_type: "Counter"
|
|
has_many :stats, dependent: :destroy, through: :character_sheet_features,
|
|
source: :featurable, source_type: "Stat"
|
|
has_many :text_fields, dependent: :destroy, through: :character_sheet_features,
|
|
source: :featurable, source_type: "TextField"
|
|
|
|
validates :name, presence: true,
|
|
length: { maximum: 255 }
|
|
|
|
scope :top_level, -> { where.missing(:parent_section) }
|
|
end
|