X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FManual%2FCookbook.pod;h=4f9fe63682a0cd9994651d86cba2d81a96525e94;hb=87980de749bd86e74b71f708237b9910790a9b87;hp=57c21756a29a3dd0637d9ec474bd8c90043dfc81;hpb=958bcea5fcf02c0c13e934dd03103d8421dcc144;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Manual/Cookbook.pod b/lib/DBIx/Class/Manual/Cookbook.pod index 57c2175..4f9fe63 100644 --- a/lib/DBIx/Class/Manual/Cookbook.pod +++ b/lib/DBIx/Class/Manual/Cookbook.pod @@ -8,9 +8,41 @@ Things that could be handy =head1 RECIPES -=head2 Input validation. +=head2 Disconnecting cleanly -=head2 Using joins +If you find yourself quitting an app with Control-C a lot during development, +you might like to put the following signal handler in your main database +class to make sure it disconnects cleanly: + + $SIG{INT} = sub { + __PACKAGE__->storage->dbh->disconnect; + }; + +=head2 Using joins and prefetch + +See L. + +=head2 Transactions + +As of version 0.04001, there is improved transaction support in +L. Here is an example of the recommended way to use it: + + my $obj = Genus->find(12); + eval { + MyDB->tx_begin; + $obj->add_to_species({ name => 'troglodyte' }); + $obj->wings(2); + $obj->update; + cromulate($obj); # can have a nested transation + MyDB->tx_commit; + }; + if ($@) { eval { MyDB->tx_rollback } } # rollback might fail, too + +Currently, a nested commit will do nothing and a nested rollback will die. +The code at each level must be sure to call rollback in the case of an error, +to ensure that the rollback will propagate to the top level and be issued. +Support for savepoints and for true nested transactions (for databases that +support them) will hopefully be added in the future. =head2 Many-to-many relationships @@ -78,8 +110,4 @@ illustrate: # book2author table equals the bookID of the books (using the bookID # relationship table -=head2 Advanced Exception handling - -=head2 Transactions - =back