simukappu/activity_notification

Dependent Destroy on Target Model

amfazlani opened this issue · 3 comments

Hi, Thank you for this gem. I had a quick question about how you would delete associated notifications when a particular model is destroyed. For example a Project model has acts_as_notifiable attached to it. But when project is deleted there are still notifications that point notifiable to that project even tho it still doesn't exist. Trying to figure out a way I can delete the associated notifications when project is deleted like 'has_many :notifications, dependent destroy' would work in other has many relationships.

You can use :dependent_notifications option in acts_as_notifiable function like this:

class Project < ActiveRecord::Base
  acts_as_notifiable :users, targets: User.all, dependent_notifications: :delete_all
end

See code document for more details. (Document server https://www.rubydoc.info seems to be currently unavailable)

Please close this issue if your questions are resolved.

Hi, sorry for the late reply. That is what I was looking for thank you. Thank you so much.