From: Jess Robinson Date: Sat, 14 Oct 2006 19:24:15 +0000 (+0000) Subject: Added examples for ResultSetColumn X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ac2803efd625dc19dd55756dc3483e3a973e0f45;p=dbsrgits%2FDBIx-Class-Historic.git Added examples for ResultSetColumn --- diff --git a/lib/DBIx/Class/Manual/Cookbook.pod b/lib/DBIx/Class/Manual/Cookbook.pod index ada12c6..7fed731 100644 --- a/lib/DBIx/Class/Manual/Cookbook.pod +++ b/lib/DBIx/Class/Manual/Cookbook.pod @@ -387,7 +387,7 @@ From 0.04999_05 onwards, C can be nested more than one relationship deep using the same syntax as a multi-step join: my $rs = $schema->resultset('Tag')->search( - undef, + {}, { prefetch => { cd => 'artist' @@ -406,6 +406,44 @@ SQL statements: my $tag = $rs->first; print $tag->cd->artist->name; +=head2 Columns of data + +If you want to find the sum of a particular column there are several +ways, the obvious one is to use search: + + my $rs = $schema->resultset('Items')->search( + {}, + { + select => [ { sum => 'Cost' } ], + as => [ 'total_cost' ], + } + ); + my $tc = $rs->first->get_column('total_cost'); + +Or, you can use the L, which gets +returned when you ask the C for a column using +C: + + my $cost = $schema->resultset('Items')->get_column('Cost'); + my $tc = $cost->sum; + +With this you can also do: + + my $minvalue = $cost->min; + my $maxvalue = $cost->max; + +Or just iterate through the values of this column only: + + while ( my $c = $cost->next ) { + print $c; + } + + foreach my $c ($cost->all) { + print $c; + } + +See L for more documentation. + =head2 Using relationships =head3 Create a new row in a related table