JackDanger / permanent_records

Rails Plugin - soft-delete your ActiveRecord records. It's like an explicit version of ActsAsParanoid
https://jdanger.com
MIT License
272 stars 64 forks source link

Force-destroying nested, permanent records not possible with foreign keys? #66

Open aried3r opened 8 years ago

aried3r commented 8 years ago

It's a bit, but not quite related to #65.

I'm trying to delete a permanent record, which has_many permanent records using record.destroy(:force), but I get stuck because referential integrity is violated by doing this.

I took a look at the specs, which try to verify that this works, but (I think) SQLite does not enforce referential integrity the way PostgreSQL does.

In the code I found this segment which seems to be the code at fault (should I be correct about my assumption). The records in the has_many association are properly being saved in dependent_records, however, the block, in this case super() gets called before, meaning that before permanent_records has a chance to indeed delete the records that are permanent, my code crashes because super throws an exception before this can happen.

aried3r commented 8 years ago

I just tested by swapping out this gem by acts_as_paranoid, it works with acts_as_paranoid, but I'd love to stick with this gem, because of the explicit scopes and the small codebase. :)

Edit: Also works with the paranoia gem.

aried3r commented 8 years ago

If I understand this code correctly, they delete the associated records first, then the record itself within a transaction.

drakmail commented 8 years ago

Today I'm launched all specs with postgresql as DB and no specs failed. Seems that the issue requiring additional specs.

danguyenedu commented 8 years ago

@aried3r @drakmail did you find a solution for this?

aried3r commented 8 years ago

@airpoli I have since switched to paranoia 2.2.0.pre.