Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:nullify_notifiable option on :dependent_notifications #140

Open
christopher-avila opened this issue Jun 11, 2020 · 2 comments
Open

:nullify_notifiable option on :dependent_notifications #140

christopher-avila opened this issue Jun 11, 2020 · 2 comments

Comments

@christopher-avila
Copy link

Problem or use case

The use case that explains this feature is for those applications which want to keep the track of notifications even if a notifiable has been destroyed. With the current implementation, we can skip deletion of dependent notifications by not passing any parameter to dependent_notifications (on acts_as_notifiable), which is the default behavior but in this case this results in having the notifiable_type and notifiable_id pointing to an unexisting record. Even if this is a correct approach, some cases needs to clean this kind of information. That's where the option of nullify_notifiable comes to action.

Expected solution

Steps to follow:

  1. Adding a new option to available_dependent_notifications_options called nullify_notifiable.
  2. Adding a new option to add_destroy_dependency for that key we defined before.
  3. Defining into the Notifiable module the new function which will update all the generated_notifications_as_notifiable_for(target_type) to notifiable_type and id to nil.

Alternatives

For this approach I did not find any easy way to do this without monkeypatching, which has been the solution I've took.

@simukappu
Copy link
Owner

simukappu commented Sep 27, 2020

I think this requested feature is clear, but just wonder what its use cases are. Are there any use cases you would like to nullify notifiable, not deleting notifications? Notifications without notifiable record do not work in your application.

Thank you for your pull request. I would appreciate it if you could write RSpec tests of this new :nullify_notifiable option.

@simukappu
Copy link
Owner

In addition, Notification model has a validation for presence of notifiable.
https://github.com/simukappu/activity_notification/blob/master/lib/activity_notification/orm/active_record/notification.rb#L51

If we add this nullify_notifiable dependent option, updated notification records will be invalid. We have to consider and design more details about this enhancement request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants