Forum: Ruby on Rails The two methods of handling deleted records. Standards?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Ronny Hanssen (Guest)
on 2006-04-18 21:02
(Received via mailing list)
Hi all,

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

Now, using this scheme for deleted records (an int column which defaults
0) seems like a very common solution amongst developers. Wouldn't it be
(and cool) if ActiveRecord knew how to leave deleted records out from
finds, except when forced to include them? I mean, then I could code the
I am normally doing, and I would only have to code extra for the cases
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
do some coding to make the delete strategy transparent.

Alternatively one could narrow it down to a delete_strategy setting,
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
be able to implement it, but if anyone is able to give me some pointers
certainly try. I guess this would be an extention to Rails, although I
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
the database.

Christian K. (Guest)
on 2006-04-18 21:35
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...
Alan F. (Guest)
on 2006-04-18 23:05
I've a feeling there's an acts_as... plugin for this somewhere....

Kevin O. (Guest)
on 2006-04-18 23:11
(Received via mailing list)
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

Ronny Hanssen (Guest)
on 2006-04-18 23:59
(Received via mailing list)
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
Well... Can't have it all :)


On 18 Apr 2006 19:08:58 -0000, Kevin O. <
This topic is locked and can not be replied to.