Re: [CDBI] HOW TO populate creation date automatically?

[prev] [thread] [next] [Date index for 2006/01/01]

From: Rhesa Rozendaal
Subject: Re: [CDBI] HOW TO populate creation date automatically?
Date: 00:37 on 01 Jan 2006
Vitaliy Babiy wrote:
> Hi 
> 
> I have table with column 'dateCreated' which supposed to have date when
> record was created. How can I populate that field automatically with
> CDBI?
> 
> I tried to use trigger 'before_create' to populate that field, but it
> doesn't work. What I'm missing here?
> 
> __PACKAGE__->add_trigger(before_create  => 
> sub { my $self = shift;                         
>       $self->_attribute_store( { dateCreated => Class::Date->now } );
>       } );


Why do you use _attribute_store here, which looks like an internal method?
I use set() as follows in my base class, and it works fine for every table 
with a create_date column:

__PACKAGE__->add_trigger(before_create => sub {
     $_[0]->set(create_date => DateTime->now)
         if       $_[0]->find_column('create_date')
            and ! $_[0]->get('create_date')
     });

HTH,
Rhesa

_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi

(message missing)

[CDBI] Simple join
Jon Molin 00:16 on 30 Dec 2005

Re: [CDBI] Simple join
Peter Speltz 20:13 on 30 Dec 2005

Re: [CDBI] HOW TO populate creation date automatically?
Rhesa Rozendaal 00:37 on 01 Jan 2006

Generated at 01:21 on 10 Jan 2006 by mariachi v0.52