class Admission::Checkbox < ApplicationRecord
  audited
  belongs_to :school

  has_many :application_checkboxes, dependent: :destroy
  has_many :applicant_checkboxes, dependent: :restrict_with_error

  has_many :applications, through: :application_checkboxes
  has_many :applicants, through: :applicant_checkboxes

  validates :name, presence: true

  scope :by_archived, ->(flag) { where(archived: flag) unless flag.nil? }

  def self.sorted
    order(:name)
  end

  def self.positioned
    order('admission_application_checkboxes.position')
  end
end
