On Monday, April 8, 2019 at 6:11:21 AM UTC-7, Chris Elsworth wrote:
>
> Hello!
>
> I've inherited a schema which is in a live app that makes heavy use of 
> "paranoid" behaviour; that is to say it has `deleted_at` columns in just 
> about every table, including join tables. I'm using the sequel-paranoid gem 
> to handle this mostly.
>
> So, I have lots of `many_to_many` associations that actually go through 
> model tables, complete with their own `deleted_at`. I guess this was so all 
> the associations can be restored along with the primary models if they need 
> to be undeleted.
>
> I'd like to use the `association_dependencies` plugin to manage deleting 
> associations automatically, but clearly none of the existing options will 
> set this `deleted_at` in the many_to_many join table. I appreciate that 
> Sequel doesn't ship with paranoid support so it would be undesirable to 
> simply add a new `:paranoid` option to `association_dependencies`.
>
> My next thought therefore was, could we specify a block for each 
> association to call our own code? I could then have something set 
> `deleted_at` on each row, instead of removing the row entirely. Would it be 
> possible to pass the dataset of rows being updated to this block? Or each 
> row individually would work too.
>
> Would this be something that cold be considered for inclusion Jeremy?
>

You should be able to do this with a database trigger, where setting 
deleted at in one table sets it on associated rows of the dependent tables.

At the model level, you can probably do what you want via:

def before_destroy
  super
  # For each association that you want to soft delete:
  association_dataset.update(:deleted_at=>Sequel::CURRENT_TIMESTAMP)
end

If you don't think either of those will work, can you show an example of 
what this proposed API would look like?

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to