# frozen_string_literal: true

# == Schema Information
#
# Table name: categories
#
#  id         :bigint           not null, primary key
#  deleted_at :datetime
#  name       :string(191)
#  ord        :integer          default(0)
#  created_at :datetime         not null
#  updated_at :datetime         not null
#  user_id    :bigint
#
# Indexes
#
#  index_categories_on_name  (name) UNIQUE
#
class Category < ApplicationRecord
  has_many :article_categories
  has_many :articles, through: :article_categories, source: "article"
  belongs_to :user, optional: true

  def self.list_names(limit)
    Category.where(deleted_at: nil).order(ord: :desc).limit(limit).map(&:name).join(",")
  end
end
