From: Jess Robinson Date: Wed, 29 Mar 2006 15:30:55 +0000 (+0000) Subject: ResultSetManager example from CaptainCarlos X-Git-Tag: v0.06001~19 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d6ed6a67c8fd8b7fe10511cb9cf197299252a14c;p=dbsrgits%2FDBIx-Class.git ResultSetManager example from CaptainCarlos --- diff --git a/lib/DBIx/Class/Manual/Cookbook.pod b/lib/DBIx/Class/Manual/Cookbook.pod index 5690f43..1490585 100644 --- a/lib/DBIx/Class/Manual/Cookbook.pod +++ b/lib/DBIx/Class/Manual/Cookbook.pod @@ -200,6 +200,26 @@ Then call your new method in your code: my $ordered_cds = $schema->resultset('CD')->search_cds_ordered(); +=head3 Predefined searches without writing a ResultSet class + +Alternatively you can automatically generate a DBIx::Class::ResultSet +class by using the ResultSetManager component and tagging your method +as ResultSet: + + __PACKAGE__->load_components(qw/ ResultSetManager Core /); + + sub search_cds_ordered : ResultSet { + my ($self) = @_; + return $self->search( + {}, + { order_by => 'name DESC' }, + ); + } + +Then call your method in the same way from your code: + + my $ordered_cds = $schema->resultset('CD')->search_cds_ordered(); + =head2 Using joins and prefetch You can use the C attribute to allow searching on, or sorting your