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

Add dependent: :destroy on snapshots #40

Open
Judobob opened this issue Apr 25, 2023 · 1 comment
Open

Add dependent: :destroy on snapshots #40

Judobob opened this issue Apr 25, 2023 · 1 comment
Labels
documentation Improvements or additions to documentation not-a-bug Not a bug

Comments

@Judobob
Copy link

Judobob commented Apr 25, 2023

Is it possible to add in the future the ability to have dependent delete on the snapshots? If a user removes himself from our app we would like to have all his snapshots removed also without having to do it through a method manually.

@westonganger
Copy link
Owner

westonganger commented May 1, 2023

There is this comment in the readme

Destroy snapshot and all its child snapshots
must be performed manually, snapshots and snapshot items are NEVER destroyed automatically

My initial reaction is that I want to keep that approach.

However as I think about it, if you are deleting the record than its probable that you would want the snapshots deleted too. If you really wanted to keep the snapshots I suspect you would actually mark your record as inactive/archived.

Maybe an option could be helpful.

As it stands however I think its easy enough to just modify your destroy method, even if it does seem a little non-intuitive.

class User < ApplicationRecord
  def destroy
    destroyed = super
    if destroyed
      Snapshot.where(item_type: self.class.name, item_id: id).destroy_all
    end
    return destroyed
  end
end

@westonganger westonganger changed the title deletion of snapshots Add dependent: :destroy on snapshots May 1, 2023
@westonganger westonganger added the not-a-bug Not a bug label Aug 21, 2024
@westonganger westonganger added the documentation Improvements or additions to documentation label Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation not-a-bug Not a bug
Projects
None yet
Development

No branches or pull requests

2 participants