# frozen_string_literal: true

# == Schema Information
#
# Table name: taggings
#
#  id         :bigint           not null, primary key
#  created_at :datetime         not null
#  updated_at :datetime         not null
#  article_id :bigint
#  tag_id     :bigint
#  user_id    :bigint
#
# Indexes
#
#  index_taggings_on_article_id             (article_id)
#  index_taggings_on_tag_id                 (tag_id)
#  index_taggings_on_tag_id_and_article_id  (tag_id,article_id) UNIQUE
#  index_taggings_on_user_id                (user_id)
#
class Tagging < ApplicationRecord
  belongs_to :article, counter_cache: :tags_count
  # belongs_to :user, counter_cache: :taggings_count
  belongs_to :tag, counter_cache: :articles_count

  validates :tag_id, uniqueness: { scope: :article_id }
end
