class TagImplication < ApplicationRecord
  belongs_to :tag, class_name: 'Tag'
  belongs_to :parent_tag, class_name: 'Tag'

  validates :tag_id, presence: true, uniqueness: { scope: :parent_tag_id }
  validates :parent_tag_id, presence: true

  validate :parent_tag_mustnt_be_itself

  private

  def parent_tag_mustnt_be_itself
    if parent_tag == tag
      errors.add :parent_tag_id, '親タグは子タグと同一であってはなりません．'
    end
  end
end
