class StudentAdditionalChoice < ApplicationRecord
  include Base::StudentAdditionalChoice

  belongs_to :field, class_name: 'StudentAdditionalField', foreign_key: :SSID, inverse_of: :choices

  delegate :school, to: :field

  validates :name, presence: true, length: { maximum: 72 }, uniqueness: { scope: :field }
  validates :value, presence: true, length: { maximum: 16 }, uniqueness: { scope: :field }
  validates :order, numericality: { only_integer: true, greater_than_or_equal_to: 0 }

  scope :ordered, -> { order(:order) }
end
