ActsAsParanoid / acts_as_paranoid

ActiveRecord plugin allowing you to hide and restore records without actually deleting them.
MIT License
1.46k stars 191 forks source link

Question: Skip recover functionality #267

Open vitalinfo opened 2 years ago

vitalinfo commented 2 years ago

@mvz What do you think about skip recover functionality? This feature could be helpful for nested objects, where you will be able to mark object as skippable for recover (in the before_recover hook) If you approve it, I can prepare the PR with implementation

mvz commented 2 years ago

Hi @vitalinfo I'm not sure what you have in mind. Can you give a code example of how this would be used?

In any case, you can prevent nested objects from being recovered by using parent.recover(recursive: false), and then recover selected nested objects manually.

vitalinfo commented 2 years ago

@mvz yes, you are right for common case, but if you need some additional logic, like: you have a user, user has f.e. comments, both models are paranoid. User is able to remove comment and user could be removed as well. On user recover we need to recover all his comments, except comments which user removed by him self.

mvz commented 2 years ago

Assuming that you have some way to know which comments were deleted by the user, that would be something like:

user.recover(recursive: false)
user.comments.with_deleted.not_removed_by_user.recover
vitalinfo commented 2 years ago

@mvz yes, this will work, but if user model has a lot of associations, the recover complexity will be huge

mvz commented 2 years ago

@vitalinfo and how will this feature help with that? What would the code look like?

vitalinfo commented 2 years ago

I'll do this feature, in worse case I'll use fork in my project