class ContactCategory < ApplicationRecord
  include Base::ContactCategory

  default_scope { where(type: 1) }

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

  belongs_to :group, class_name: 'ContactCategoryGroup', foreign_key: :CCGID,
    inverse_of: :categories, optional: true, counter_cache: :categories_count

  has_many :category_contacts, class_name: 'ContactCategoryContact', foreign_key: :CatagoryID,
    dependent: :destroy, inverse_of: :category
  has_many :contacts, through: :category_contacts

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