# The two methods of handling deleted records. Standards?

**URL:** <https://www.ruby-forum.com/t/the-two-methods-of-handling-deleted-records-standards/58129>\
**Category:** Rails\
**Created:** [April 18, 2006, 7:02pm UTC](https://www.ruby-forum.com/t/the-two-methods-of-handling-deleted-records-standards/58129 "2006-04-18T19:02:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ronny\_Hanssen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ebca7d/32.png) [@Ronny\_Hanssen](https://www.ruby-forum.com/u/Ronny_Hanssen)\
**Post date:** [April 18, 2006, 7:02pm UTC](https://www.ruby-forum.com/t/the-two-methods-of-handling-deleted-records-standards/58129/1 "2006-04-18T19:02:28Z")

</div>

Hi all,

I am fiddling with a table of mine where I have chosen to use a column  
for  
tracking whether the row is deleted or not. If I chose the normal method  
of  
physically deleting the rows then everything is fine. But, since I am  
now  
using this alternative method I have to change a lot of code to make it  
work  
“out of the box”, by adding :constraints clauses here and there. Also I  
have  
to override the delete/destroy methods to handle this different scheme.

Now, using this scheme for deleted records (an int column which defaults  
to  
0) seems like a very common solution amongst developers. Wouldn’t it be  
nice  
(and cool) if ActiveRecord knew how to leave deleted records out from  
it’s  
finds, except when forced to include them? I mean, then I could code the  
way  
I am normally doing, and I would only have to code extra for the cases  
when  
I really want to find the deleted records (normally the find is only for  
these or for one of them). Also, this would make it easier to switch  
delete\_strategy later on as well.

I was hoping for a general purpose :before\_find filter, which I could  
use to  
add the :constraints settings. Such a solution could be utilized in many  
other ways too I guess. But, unfortunately there is no such thing in  
ActiveRecord. Using this approach could be good, but I would still need  
to  
do some coding to make the delete strategy transparent.

Alternatively one could narrow it down to a delete\_strategy setting,  
which  
is either :physical or :logical (which means it is persisted, but to be  
disregarded). Default is of course physical. I am myself to new to Ruby  
to  
be able to implement it, but if anyone is able to give me some pointers  
I’d  
certainly try. I guess this would be an extention to Rails, although I  
must  
admit that I’d like this to be a part of the standard Rails  
distribution. At  
least if there was extra functionality for handling the deleted records  
in  
the database.

Regards,  
Ronny

---

<div class="post-metadata">

**Author:** ![Ronny\_Hanssen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ebca7d/32.png) [@Ronny\_Hanssen](https://www.ruby-forum.com/u/Ronny_Hanssen)\
**Post date:** [April 18, 2006, 7:35pm UTC](https://www.ruby-forum.com/t/the-two-methods-of-handling-deleted-records-standards/58129/2 "2006-04-18T19:35:04Z")

</div>

Yep that would definitely be cool. I would say you create a new class  
BetterRecord that inherits from ActiveRecord and overrides/extends the  
mentioned methods.

On the other hand, ActiveRecord does a huge load of class/object  
manipulation (adding all those methods and stuff) and makes sure  
dependent rows are being deleted too…

---

<div class="post-metadata">

**Author:** ![Ronny\_Hanssen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ebca7d/32.png) [@Ronny\_Hanssen](https://www.ruby-forum.com/u/Ronny_Hanssen)\
**Post date:** [April 18, 2006, 9:05pm UTC](https://www.ruby-forum.com/t/the-two-methods-of-handling-deleted-records-standards/58129/3 "2006-04-18T21:05:29Z")

</div>

I’ve a feeling there’s an acts\_as… plugin for this somewhere…

Alan

---

<div class="post-metadata">

**Author:** ![Ronny\_Hanssen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ebca7d/32.png) [@Ronny\_Hanssen](https://www.ruby-forum.com/u/Ronny_Hanssen)\
**Post date:** [April 18, 2006, 9:11pm UTC](https://www.ruby-forum.com/t/the-two-methods-of-handling-deleted-records-standards/58129/4 "2006-04-18T21:11:39Z")

</div>

I seem to recall a plugin that does this… acts\_as\_paranoid, I think.

On Tuesday, April 18, 2006, at 7:01 PM, Ronny Hanssen wrote:

> be able to implement it, but if anyone is able to give me some pointers I’d  
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

\_Kevin

---

<div class="post-metadata">

**Author:** ![Ronny\_Hanssen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ebca7d/32.png) [@Ronny\_Hanssen](https://www.ruby-forum.com/u/Ronny_Hanssen)\
**Post date:** [April 18, 2006, 9:59pm UTC](https://www.ruby-forum.com/t/the-two-methods-of-handling-deleted-records-standards/58129/5 "2006-04-18T21:59:02Z")

</div>

I knew it had to exist:)

Thanks for the pointers. I am about to feel a little paranoid I guess…

I would feel more comfortable if this was a part of the rails core  
though…  
Well… Can’t have it all 🙂

Ronny

On 18 Apr 2006 19:08:58 -0000, Kevin O. \<
