From: Jess Robinson Date: Mon, 20 Mar 2006 18:14:35 +0000 (+0000) Subject: Add predefined searches patch from Hartmaier Alexander X-Git-Tag: v0.06000~56 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=74dc2edcd28b6002c082c46731f703ddbfa6d318;p=dbsrgits%2FDBIx-Class.git Add predefined searches patch from Hartmaier Alexander --- diff --git a/lib/DBIx/Class/Manual/Cookbook.pod b/lib/DBIx/Class/Manual/Cookbook.pod index 715c8f8..fc3224f 100644 --- a/lib/DBIx/Class/Manual/Cookbook.pod +++ b/lib/DBIx/Class/Manual/Cookbook.pod @@ -169,6 +169,37 @@ L supports C as follows: # LEFT JOIN cd cds ON ( cds.artist = me.artistid ) # GROUP BY name +=head3 Predefined searches + +You can write your own DBIx::Class::ResultSet class by inheriting from it +and define often used searches as methods: + + package My::DBIC::ResultSet::CD; + use strict; + use warnings; + use base 'DBIx::Class::ResultSet'; + + sub search_cds_ordered { + my ($self) = @_; + + return $self->search( + {}, + { order_by => 'name DESC' }, + ); + } + + 1; + +To use your resultset, first tell DBIx::Class to create an instance of it +for you, in your My::DBIC::Schema::CD class: + + __PACKAGE__->resultset_class('My::DBIC::ResultSet::CD'); + +Then call your new method in 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