From: Peter Rabbitson Date: Thu, 28 Jan 2010 11:26:40 +0000 (+0000) Subject: RT#52681 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5176d0730ddd7a9058ad40a1ce9ddc09cc560306;p=dbsrgits%2FDBIx-Class-Historic.git RT#52681 --- diff --git a/lib/DBIx/Class/Manual/Cookbook.pod b/lib/DBIx/Class/Manual/Cookbook.pod index 8082ebf..fc7891c 100644 --- a/lib/DBIx/Class/Manual/Cookbook.pod +++ b/lib/DBIx/Class/Manual/Cookbook.pod @@ -1821,12 +1821,27 @@ You can accomplish this by overriding C on your objects: sub insert { my ( $self, @args ) = @_; $self->next::method(@args); - $self->cds->new({})->fill_from_artist($self)->insert; + $self->create_related ('cds', \%initial_cd_data ); return $self; } -where C is a method you specify in C which sets -values in C based on the data in the C object you pass in. +If you want to wrap the two inserts in a transaction (for consistency, +an excellent idea), you can use the awesome +L: + + sub insert { + my ( $self, @args ) = @_; + + my $guard = $self->result_source->schema->txn_scope_guard; + + $self->next::method(@args); + $self->create_related ('cds', \%initial_cd_data ); + + $guard->commit; + + return $self + } + =head2 Wrapping/overloading a column accessor