update cookbook and resultset docs
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Manual / Cookbook.pod
index 57c2175..4f9fe63 100644 (file)
@@ -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<DBIx::Class::ResultSet/Attributes>.
+
+=head2 Transactions
+
+As of version 0.04001, there is improved transaction support in
+L<DBIx::Class::Storage::DBI>. 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