class Covid::FormSection < ApplicationRecord
  audited

  belongs_to :school

  has_many :fields, foreign_key: :section_id, class_name: 'Covid::FormField',
    dependent: :restrict_with_error
  has_many :questions, foreign_key: :section_id, class_name: 'Covid::FormQuestion'
  has_many :displays, foreign_key: :section_id, class_name: 'Covid::FormDisplay'

  validates :title, :sequence, presence: true

  scope :ordered, -> { order(:sequence) }
  scope :by_employee_field, ->(flag) { where(employee_field: flag.present?) }
end
