ActsAsParanoid / acts_as_paranoid

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

How can I destroy models without destroying their ActiveStorage associations? #284

Open pierry01 opened 2 years ago

pierry01 commented 2 years ago

Hello everyone!

Is there a way to .destroy or .destroy_all record(s) without delete the ActiveStorage association? Example: product = Product.last with 2 images attached

product.destroy product.deleted_at -> Time.current

It would be great for this behavior to work product.destroy(keep_storage: true) product.images.count -> 2

Current behavior: product.images.count -> 0 Expected behavior: product.images.count -> 2

mvz commented 2 years ago

Hi @pierry01 I edited your title a bit because it seemed to be saying the opposite of the body of your issue. Let me know if I misunderstood somehow.

pierry01 commented 1 year ago

@mvz sorry for the delay. The title is correct now, thanks!!!

You understood the problem. Does it make sense to implement a solution for this?

mvz commented 1 year ago

@pierry01 I think the associations should always be kept until the model is fully destroyed. See also the discussion in #103.

Olgagr commented 8 months ago

Is there any solution for keeping ActiveStorage attachments?