JackDanger / permanent_records

Rails Plugin - soft-delete your ActiveRecord records. It's like an explicit version of ActsAsParanoid

Home Page:https://jdanger.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

before_destroy callback fires after the record has already been marked as deleted

ahorner opened this issue · comments

This problem rears its ugly head when you have a before_destroy callback that attempts to navigate a record's associations or find a deleted record.

The set_deleted_at method performs a save! before the callbacks are ever triggered, so the record is marked as deleted before the callbacks fire, which is inconsistent with the expected order of events:

  1. before_destroy
  2. record is destroyed
  3. after_destroy

This issue is particularly noticeable when you have a default_scope applied to a model.