The two methods of handling deleted records. Standards?

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

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…

I’ve a feeling there’s an acts_as… plugin for this somewhere…

Alan

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
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

_Kevin

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 :slight_smile:

Ronny

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