ruby-destroyed_at icon indicating copy to clipboard operation
ruby-destroyed_at copied to clipboard

Ensures destroy and restore operations are wrapped in a transaction that is rolled back when the callback chain is halted

Open alecdotninja opened this issue 9 years ago • 2 comments

Without this patch, DestroyedAt#destroy does not roll back the transaction when the callback chain is halted. This deviates from the standard ActiveRecord behavior and breaks several features. It is particularly dangerous for associations using dependent: :restrict_with_error which are silently destroyed.

The same semantics have been extended to DestroyedAt#restore. I've also added a DestroyedAt#restore! and corresponding error class (DestroyedAt::RecordNotRestored) to mimic ActiveRecord::Base#destroy! and friends.

alecdotninja avatar May 12 '16 16:05 alecdotninja

Coincidently, this also solves #56.

alecdotninja avatar May 12 '16 17:05 alecdotninja

Thank you for the PR @anarchocurious, and I apologize for the delay in getting merged in.

It looks like this branch needs to be rebased, as we have a conflict based off of the work in ae82efb1ee0dcaaf9c6400ddb4f08d60f3ef19f2. Please ping me when you have a chance to rebase and I will get this merged in.

Thanks!

michaeldupuisjr avatar Jul 11 '16 18:07 michaeldupuisjr