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