Retrospring/app/models/relationship.rb

27 lines
603 B
Ruby
Raw Normal View History

2014-11-30 05:06:05 -08:00
class Relationship < ActiveRecord::Base
2014-11-30 05:43:35 -08:00
belongs_to :source, class_name: 'User'
belongs_to :target, class_name: 'User'
validates :source_id, presence: true
validates :target_id, presence: true
2014-12-14 05:58:29 -08:00
2014-12-28 12:40:33 -08:00
after_create do
Notification.notify target, self
# increment counts
source.increment! :friend_count
target.increment! :follower_count
end
before_destroy do
Notification.denotify target, self
# decrement counts
source.decrement! :friend_count
target.decrement! :follower_count
end
2014-12-14 05:58:29 -08:00
def notification_type(*_args)
Notifications::StartedFollowing
end
2014-11-30 05:06:05 -08:00
end