views:

140

answers:

1

I have created an ActiveRecord for a customer, and now they would like it so when it's destroyed, it is actually kept around for a manual rollback.

What I would like to do is create a boolean attribute called 'active', and it defaults to 1. When a record is destroyed, the attribute is toggled to 0.

I know I could change all my queries to have an extra condition of active=1, or use scoping, or even use the type column and inheritance (which is what I'm doing to complete it ASAP).

Is there any way to tell an ActiveRecord that a record in the table is actually a record ONLY if an attribute is a certain value (in this case active=1), and if it's anything else, completely ignore it?

Thanks, Andrew

+4  A: 

This is what you want:

http://ar-paranoid.rubyforge.org/

jonnii
That looks useful. I have some :dependent => destroy associations. Do you know how acts_as_paranoid will handle this?
Andrew Ferk
should handle them just fine. dependent => :destroy invokes callbacks. Review the source for this plugin and do write some simple tests though.
Brian Hogan