association destroy should be defered and callbacks should be deferred to destroy! #12

Closed
bryanw412 opened this Issue Sep 23, 2010 · 1 comment

Comments

Projects
None yet
2 participants

Please tell me that i'm missing something idiotic and it works the way I expect it to.

It seems you have to either add acts as archived to every model associated with the record you want to archive or you have to call destroy_without_callbacks() on the object.

The first technique will only cause the associations that are :dependent=>destroy to also be destroyed in a way that's recoverable but it won't reverse the effects of before_/after_destroy callbacks. Since paperclip and most everything else use the callbacks to do their cleanup, attachments, for example, will be forever gone.

The second techique uses destroy_without_callbacks() instead of destroy(). This causes acts_as_archived to just use sql to move the record over to the archive table and bypasses all association dependent destroys and all cleanup by paperclip and like. That means that everything is still in place. ...and it's super quick! but, there is a downside. everything has to be carefully checked to make sure it's ready for a missing user_profile. Since conversations still show up in multiple places, you can still see lingering traces of this user_profile that doesn't technically exist.

The bigger killer with the later technique is that the destroy callbacks and association destroys don't get called when you destroy archived object :( I would have expected that if I find an object in the archive, that was deleted via destroy without callbacks, and then call destroy on the archived instance, it would then call all of the destroy callbacks and association :dependent=>:destroy.

Thanks for sharing this otherwise great piece of work,

~b

Owner

winton commented Jan 5, 2011

Thank you so much for putting so much into this feedback. Though you did not receive an immediate reply, I certainly took it all in.

I'm happy to tell you that archiving associations now works with version 0.3.0 (as does Rails 3). I would love to have some feedback on it before announcing it publicly.

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment