[prev] [thread] [next] [Date index for 2004/05/20]
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 After the related* March thread, I followed the conclusions and replaced all my direct member access from my before_create triggers with calls to find_column / _attribute_store ... *( Date: Sun, 21 Mar 2004 12:38:54 +0200 (EET) Subject: RFC wanted (was Re: Simple trigger question) Message-ID: <Pine.LNX.4.53.0403211230560.4011@xxx.xxx> ) ... until CDBI 0.96 everything was fine, but the new magic implemented regarding auto_increments* crashes this approach. *( If you are using a database with AUTO_INCREMENT (e.g. MySQL) then you do not need this, and any call to create() without a primary key specified will fill this in automagically ) Scenario: __PACKAGE__->table('CDs'); __PACKAGE__->columns(Primary => qw/id/); ... my $id_col = __PACKAGE__->find_column('id'); my $name_col = __PACKAGE__->find_column('name'); __PACKAGE__->add_trigger(before_create => sub { my $self = shift; # "safe" approach: # unless ($self->_attribute_exists($id_col)) { # $self->_attribute_store($id_col, bake_id($self->_attrs($name_col))); # } # "direct" approach: $self->{id} ||= bake_id($self->{name}); }; ... # in main: $cds->create({name => 'Foobar'}); If using the "safe" approach, all I get now is: Can't insert new CDs: Can't get last insert id at ... (while using "direct" approach work as expected). Did I miss something in the "safe" approach? TIA. - -- marius feraru http://altblue.com/ "It isn't easy being the parent of a two-years-old. However, it's a pretty small price to pay for having somebody around the house who understands computers." -----BEGIN PGP SIGNATURE----- iD8DBQFArTqIn0ZKufYp8iURApwwAJ9WmlB1qsflDFzh/3r0oP+97ZrVsQCffWbj mKLy1kVrzFg/0BJErD39p1A= =yWpO -----END PGP SIGNATURE-----
before_create trigger problem with cdbi 0.96
|
Generated at 11:34 on 01 Dec 2004 by mariachi v0.52