# frozen_string_literal: true

# == Schema Information
#
# Table name: components
#
#  id             :bigint           not null, primary key
#  articles_count :integer          default(0)
#  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_components_on_name  (name) UNIQUE
#
class Component < ApplicationRecord
  has_many :article_components
  has_many :articles, through: :article_components, source: "article"

  belongs_to :user, optional: true

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