2017-02-11 00:20:42 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-11-25 11:23:47 -08:00
|
|
|
class Follow < ApplicationRecord
|
2017-02-11 00:20:42 -05:00
|
|
|
belongs_to :user
|
|
|
|
belongs_to :followed, polymorphic: true
|
|
|
|
has_one :follow_reason, dependent: :destroy
|
2017-11-25 11:23:47 -08:00
|
|
|
|
2017-02-11 00:20:42 -05:00
|
|
|
validates :user, presence: true
|
|
|
|
validates :followed, presence: true
|
|
|
|
validates :user, uniqueness: { scope: :followed, message: 'This entity is already followed by this user' }
|
2017-11-25 11:23:47 -08:00
|
|
|
|
2017-02-11 00:20:42 -05:00
|
|
|
after_create :add_subsetting
|
2017-09-08 13:17:42 -04:00
|
|
|
|
2018-01-21 14:21:00 -08:00
|
|
|
scope :active, (-> { where(muted: false) })
|
2017-09-08 13:17:42 -04:00
|
|
|
|
2017-02-11 00:20:42 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def add_subsetting
|
2018-01-21 14:21:00 -08:00
|
|
|
FollowReason.create!(follow: self)
|
2017-02-11 00:20:42 -05:00
|
|
|
end
|
|
|
|
end
|