[Dbix-class] pod patch for predefined searches using a custom resultset

Hartmaier Alexander Alexander.Hartmaier at t-systems.at
Mon Mar 20 18:24:49 CET 2006


*snip*
Index: lib/DBIx/Class/Manual/Cookbook.pod
===================================================================
--- lib/DBIx/Class/Manual/Cookbook.pod  (revision 1261)
+++ lib/DBIx/Class/Manual/Cookbook.pod  (working copy)
@@ -169,6 +169,37 @@
   # 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;
+
+If you want to use the resultset class by default for one of your table classes
+you can do this by defining it in your table class like this:
+
+  __PACKAGE__->resultset_class('My::DBIC::ResultSet::CD');
+      
+
+To just use the resultset somewhere in your code you have to call:
+
+   $schema->source('CD')->resultset_class('My::DBIC::ResultSet::CD');
+
 =head2 Using joins and prefetch
 
 You can use the C<join> attribute to allow searching on, or sorting your
*snip*


-Alex

*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH
Rennweg 97-99, 1030 Wien
Telefon +43 (0)57057 0, Telefax +43 (0)57057 8155
Bank Austria AG, BLZ 12000, Kto. 233-111-674/00, IBAN AT291200023311167400
Handelsgericht Wien, FN 79340b – DVR Nr. 0713520 – ARA-Lizenz Nr. 12554
ATU 15169001

*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Hinweis: Dieses E-mail kann vertrauliche und geschützte Informationen enthalten.
Sollten Sie nicht der beabsichtigte Empfänger sein, verständigen Sie bitte den Absender und löschen Sie dieses E-mail dann sofort.

Notice: This e-mail contains information that is confidential and may be privileged.
If you are not the intended recipient, please notify the sender and then delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*


More information about the Dbix-class mailing list