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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community 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
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
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....

Alan
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
>removed_email_address@domain.invalid
>http://lists.rubyonrails.org/mailman/listinfo/rails
>


_Kevin
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
though...
Well... Can't have it all :)

Ronny


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