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