X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FManual%2FCookbook.pod;h=3e5aa7b61870a9e8f4784c6e6399ad76ffd96c1a;hb=541df64afe67cde2a5cd2c48c1cb419298452a1f;hp=7806b089123ab36bf47f6fc0b8fa19d8b0c6d4e5;hpb=321d9634cc6befb5a7704e15f3027927eab8952a;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Manual/Cookbook.pod b/lib/DBIx/Class/Manual/Cookbook.pod index 7806b08..3e5aa7b 100644 --- a/lib/DBIx/Class/Manual/Cookbook.pod +++ b/lib/DBIx/Class/Manual/Cookbook.pod @@ -544,7 +544,7 @@ To order C<< $book->pages >> by descending page_number. =head2 Transactions As of version 0.04001, there is improved transaction support in -L and L. Here is an +L and L. Here is an example of the recommended way to use it: my $genus = $schema->resultset('Genus')->find(12); @@ -964,7 +964,7 @@ method. =head2 Profiling -When you enable L's debugging it prints the SQL +When you enable L's debugging it prints the SQL executed as well as notifications of query completion and transaction begin/commit. If you'd like to profile the SQL you can subclass the L class and write your own profiling @@ -1159,42 +1159,18 @@ B test.pl DBIx::Class is not built for speed, it's built for convenience and ease of use, but sometimes you just need to get the data, and skip the -fancy objects. Luckily this is also fairly easy using -C: - - # Define a class which just returns the results as a hashref: - package My::HashRefInflator; - - ## $me is the hashref of cols/data from the immediate resultsource - ## $prefetch is a deep hashref of all the data from the prefetched - ## related sources. - - sub mk_hash { - my ($me, $rest) = @_; - - return { %$me, - map { ($_ => mk_hash(@{$rest->{$_}})) } keys %$rest - }; - } - - sub inflate_result { - my ($self, $source, $me, $prefetch) = @_; - return mk_hash($me, $prefetch); - } - - # Change the object inflation to a hashref for just this resultset: - $rs->result_class('My::HashRefInflator'); - - my $datahashref = $rs->next; - foreach my $col (keys %$datahashref) { - if(!ref($datahashref->{$col})) { - # It's a plain value - } - elsif(ref($datahashref->{$col} eq 'HASH')) { - # It's a related value in a hashref - } - } - +fancy objects. + +To do this simply use L. + + my $rs = $schema->resultset('CD'); + + $rs->result_class('DBIx::Class::ResultClass::HashRefInflator'); + + my $hash_ref = $rs->find(1); + +Wasn't that easy? + =head2 Get raw data for blindingly fast results If the C solution above is not fast enough for you, you