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

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

Open
pierry01 opened this issue Jun 17, 2022 · 4 comments

Comments

@pierry01
Copy link

pierry01 commented Jun 17, 2022

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

@pierry01 pierry01 changed the title Does not destroy ActiveStorage Does not destroy ActiveStorage associations Jun 17, 2022
@mvz mvz changed the title Does not destroy ActiveStorage associations How can I destroy models without destroying their ActiveStorage associations? Jun 18, 2022
@mvz
Copy link
Contributor

mvz commented Jun 18, 2022

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
Copy link
Author

@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
Copy link
Contributor

mvz commented Aug 12, 2022

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

@Olgagr
Copy link

Olgagr commented Dec 5, 2023

Is there any solution for keeping ActiveStorage attachments?

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

No branches or pull requests

3 participants