class StudentCategory < ApplicationRecord
  include Base::StudentCategory

  associations_for legacy: true do |a|
    a.belongs_to :school
  end

  belongs_to :group, class_name: 'StudentCategoryGroup', foreign_key: :SCGID,
    inverse_of: :categories

  has_many :category_students, foreign_key: :SCID, dependent: :destroy, inverse_of: :category
  has_many :students, through: :category_students

  validates :name, presence: true, length: { maximum: 32 }
  validates :description, length: { maximum: 128 }

  scope :by_group, ->(ids) { where(group_id: ids) if ids }
end
