profile_follower.rb
957 Bytes
class ProfileFollower < ApplicationRecord
self.table_name = :profiles_circles
track_actions :new_follower, :after_create, :keep_params => ["follower.name", "follower.url", "follower.profile_custom_icon"], :custom_user => :profile
attr_accessible :profile, :circle
#TODO -> user being followed
belongs_to :profile, :polymorphic => true
belongs_to :circle
#TODO -> circle owner
# has_one :person, through: :circle, source_type: "ProfileFollower"
def circle_owner
self.circle.owner
end
alias follower circle_owner
validates_presence_of :profile_id, :circle_id
validates :profile_id, :uniqueness => {:scope => :circle_id, :message => "can't put a profile in the same circle twice"}
scope :with_follower, -> person{
joins(:circle).where('circles.owner_id = ?', person.id)
}
scope :with_profile, -> profile{
where(:profile => profile)
}
scope :with_circle, -> circle{
where(:circle => circle)
}
end