X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FManual%2FCookbook.pod;h=7e9a810969b89da1a423b76f20f3b802767b51a0;hb=81791ac391d1bcdb0de614f5317ab9966d806488;hp=f83d7ee027ea35e8fa2143ab8d2a77dba323a037;hpb=14574c41f268be47c9b54270b9e10421d9ea656e;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/Manual/Cookbook.pod b/lib/DBIx/Class/Manual/Cookbook.pod index f83d7ee..7e9a810 100644 --- a/lib/DBIx/Class/Manual/Cookbook.pod +++ b/lib/DBIx/Class/Manual/Cookbook.pod @@ -313,9 +313,8 @@ L has now prefetched all matching data from the C table, so no additional SQL statements are executed. You now have a much more efficient query. -Note that as of L 0.04, C cannot be used with -C relationships. You will get an error along the lines of "No -accessor for prefetched ..." if you try. +Note that as of L 0.05999_01, C I be used with +C relationships. Also note that C should only be used when you know you will definitely use data from a related table. Pre-fetching related tables when you @@ -410,24 +409,22 @@ example of the recommended way to use it: my $genus = $schema->resultset('Genus')->find(12); + my $coderef2 = sub { + $genus->extinct(1); + $genus->update; + }; + my $coderef1 = sub { - my ($schema, $genus, $code) = @_; $genus->add_to_species({ name => 'troglodyte' }); $genus->wings(2); $genus->update; - $schema->txn_do($code, $genus); # Can have a nested transaction + $schema->txn_do($coderef2); # Can have a nested transaction return $genus->species; }; - my $coderef2 = sub { - my ($genus) = @_; - $genus->extinct(1); - $genus->update; - }; - my $rs; eval { - $rs = $schema->txn_do($coderef1, $schema, $genus, $coderef2); + $rs = $schema->txn_do($coderef1); }; if ($@) { # Transaction failed @@ -719,11 +716,11 @@ redispatches your call to store_column to the superclass(es). You might have a class C which has many Cs. Further, you want to create a C object every time you insert an C object. -You can accomplish this by overriding C: +You can accomplish this by overriding C on your objects: sub insert { - my ( $class, $args_ref ) = @_; - my $self = $class->next::method($args_ref); + my ( $self, @args ) = @_; + $self->next::method(@args); $self->cds->new({})->fill_from_artist($self)->insert; return $self; }