# == Schema Information
#
# Table name: likes
#
#  id            :integer          not null, primary key
#  likeable_id   :integer
#  likeable_type :string
#  user_id       :integer
#  created_at    :datetime         not null
#  updated_at    :datetime         not null
#

class Like < ApplicationRecord
  # *current_user* likes *likeable*
  # *current_user* unlikes *likeable*
  include Trackable

  belongs_to :likeable, polymorphic: true, counter_cache: true
  belongs_to :user

  validates_presence_of :user, :likeable
  validates :user_id, uniqueness: { scope: [:likeable_id, :likeable_type] }

  def recipient
    likeable
  end
end