My adventures with acts_as_paranoid and Rails 2
Who's paranoid? Me? Never... Are you saying I'm paranoid? What makes you think I'm paranoid? Am I doing something to make you think I'm paranoid... Maybe you're paranoid... er...
Okay, so I'm not necessarily paranoid (or am I?) but, I have been dealing with an application that is. How is my application paranoid? It uses the Rails plugin, acts_as_paranoid. In dealing with this application, the need has come along to undelete some of the deleted data. The beauty of acts_as_paranoid is that when you utilize the plugin in a Rails application, your data isn't really deleted. In each table, you add a nice little column with the name of deleted_at, and when you delete something, rather than destroying the record, it puts a timestamp in that field on whatever row you deleted. It also follows the chain of relationships.
After reading up on the plugin and spending days wading around code, I learned that acts_as_paranoid also overrides the Find methods in ActiveRecord. The one feature that I really wish it did have, however, was a restore or undelete feature. Perhaps I'm utilizing it wrong - there's a great chance that is the case, however, given the number of has many relationships I have going on in my database, I'm really struggling with undeleting things.
In the meantime, I've been looking at other plugins such as acts_as_trashable, acts_as_restorable, and a plugin that deals with scope. Some of the other plugins serialize and move data to another table, but I'm not completely comfortable with the idea of moving data. What happens if something happens in the midst of that move? It just makes me a little uneasy. Call me a control freak. I won't be offended.
So, I've got to contemplate how I want to deal with the conundrum on my hands. I have the need to show all records, and be able to undelete records that are deleted.
If any of you who read this blog happen to have this type of experience with Ruby on Rails and the acts_as_paranoid plugin, I'd love your comments.
And with that, I am off... more coding, more fun.
Trackbacks
Use the following link to trackback from your own site:
http://www.mindfuliterations.com/articles/trackback/144
Comments
-
So what approach did you settle on? I'm trying to decide myself and I'd be curious to see how you made out.
-
I ended up writing a custom thing built to the codebase. I got the okay to kill the 'deleted' data and then implemented an 'active' field in the different tables. The way that the relationships were built out, there wasn't any 'good way' to check the right parent, so I basically put in logic to check the specific parent and go up the line to see if it was active. It's hard to go back when it's already implemented. I also did a lot of searching and didn't find any good way to undelete the data. Which, is why I settled on the approach I ended up taking. Let me know what you decide to do!