Skip to content

Commit

Permalink
When an Activity is destroyed, any related Notification is sought and…
Browse files Browse the repository at this point in the history
… destroyed
  • Loading branch information
Roendal committed Jul 8, 2011
1 parent 5044871 commit af7c998
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/models/activity.rb
Expand Up @@ -80,7 +80,7 @@ class Activity < ActiveRecord::Base
}

after_create :increment_like_count
after_destroy :decrement_like_count
after_destroy :decrement_like_count, :delete_notifications


#For now, it should be the last one
Expand Down Expand Up @@ -258,4 +258,13 @@ def decrement_like_count

direct_activity_object.decrement!(:like_count)
end

# after_destroy callback
#
# Destroy any Notification linked with the activity
def delete_notifications
Notification.find_by_object(self).each do |notification|
notification.destroy
end
end
end

0 comments on commit af7c998

Please sign in to comment.