On Tue, Feb 17, 2009 at 1:21 PM, Jesse Sheidlower <[email protected]> wrote:

> On Mon, Feb 16, 2009 at 01:49:08PM -0600, fREW Schmidt wrote:
> > Hello friends!
> >
> > I am sure there is a better term for this, I just don't know what it is.
>  I
> > would like for my database to have some type of removal field that would
> > effectively mark a row as deleted without deleting it.  I've seen ORMs
> that
> > do this before and I was wondering if DBIC did something or had support
> for
> > something like this.
> >
> > To make myself more clear, I'd like either a binary flag or a date which
> > would probably be called deleted or date_deleted or is_deleted (feel free
> to
> > give input in this) and I'd like it not to show up in regular resultsets
> > unless I explicitly say I want to see the deleted rows.
> >
> > Thoughts?
>
> Other people have made what are probably more robust
> suggestions.  However, what I do in my apps is very similar to
> what you're asking for here:
>
> In any table to which this applies, I have a field called
> "deleted" defined as "datetime default NULL". When I want to
> delete a field, I have this in my do_delete() routine:
>
>  my $record = $c->stash->{model}->find($id); # add error-checking
>  $record->deleted(\'now()');
>  $record->update;
>
> Then, in my ResultSet class I just have this:
>
> # only find non-deleted records
> __PACKAGE__->resultset_attributes({ where => { deleted => undef } });
>
> Presto, any normal search, find, etc. operation will always
> only find the non-deleted records; I don't have to think about
> the fact that the "deleted" ones are still in the database,
> just with a flag set. It's transparent to the user.
>
> I could have sworn that I wrote this into a cookbook entry,
> but I can't find it now.
>
> Jesse Sheidlower
>

I wrote a blog post on the specifics of my method.
http://blog.afoolishmanifesto.com/archives/274.  The only things that are
missing are a) configurability and b) a way to find deleted rows.  The first
is just a matter of me reading the source code of more Components, the
second seems harder as I can't seem to pull it off with the information that
people on IRC are giving me.  I'll email you guys about the solution to that
when I get it.


-- 
fREW Schmidt
http://blog.afoolishmanifesto.com
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]

Reply via email to