Skip to content
Snippets Groups Projects
Forked from PortalMEC / portalmec
1205 commits behind the upstream repository.
follow.rb 631 B
# == Schema Information
#
# Table name: follows
#
#  id              :integer          not null, primary key
#  followable_id   :integer
#  followable_type :string
#  user_id         :integer
#  created_at      :datetime         not null
#  updated_at      :datetime         not null
#

class Follow < ApplicationRecord
  # *current_user* follows *followable*
  include Trackable

  belongs_to :followable, polymorphic: true, counter_cache: true
  belongs_to :user

  validates_presence_of :user, :followable
  validates :user_id, uniqueness: { scope: [:followable_id, :followable_type] }

  def recipient
    followable
  end
end