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

Vitaliy Babiy vitaliy.babiy at gmail.com
Mon Jan 9 00:25:08 GMT 2006


Hey

> In general, you don't want to use set() or get() from inside a trigger, since
> they invoke triggers themselves. _attribute_store() is the correct method to
> use here. Refer to the documentation for evidence:
> 
> http://search.cpan.org/dist/Class-DBI/lib/Class/DBI.pm#LOW-LEVEL_DATA_ACCESS

This exactly what I'm doing. But I can not understand why it's not
working. Am I missing something?


__PACKAGE__->add_trigger( before_create  => 
     sub { my $self = shift;                         
           $self->_attribute_store( { 
                   dateCreated => Class::Date->now } );
         } );

I checked log and it's obvious that 'dateCreated' field is not populated
when record is created in DB. I use MySQL, by the way.

Regards, Vitaliy





More information about the ClassDBI mailing list