X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FManual%2FCookbook.pod;h=7d0de14b3313034ed973c40ecd828794a54fb0aa;hb=dcdf7b2cd485cc015ddbfd816f6735be075c3386;hp=5d56802ab04c864ea631b090fdbce22b9bb054cf;hpb=70bb942d89a34bc025ecf75f750c57fc9d2f4109;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Manual/Cookbook.pod b/lib/DBIx/Class/Manual/Cookbook.pod index 5d56802..7d0de14 100644 --- a/lib/DBIx/Class/Manual/Cookbook.pod +++ b/lib/DBIx/Class/Manual/Cookbook.pod @@ -19,19 +19,8 @@ paged resultset, which will fetch only a defined number of records at a time: return $rs->all(); # all records for page 1 -The C attribute does not have to be specified in your search: - - my $rs = $schema->resultset('Artist')->search( - undef, - { - rows => 10, - } - ); - - return $rs->page(1); # DBIx::Class::ResultSet containing first 10 records - -In either of the above cases, you can get a L object for the -resultset (suitable for use in e.g. a template) using the C method: +You can get a L object for the resultset (suitable for use +in e.g. a template) using the C method: return $rs->pager(); @@ -116,7 +105,7 @@ reference (this is a feature of L). Say you want to run a complex custom query on your user data, here's what you have to add to your User class: - package My::Schema::User; + package My::Schema::Result::User; use base qw/DBIx::Class/; @@ -160,10 +149,10 @@ files (instead of stuffing all of them into the same resultset class), you can achieve the same with subclassing the resultset class and defining the ResultSource there: - package My::Schema::UserFriendsComplex; + package My::Schema::Result::UserFriendsComplex; - use My::Schema::User; - use base qw/My::Schema::User/; + use My::Schema::Result::User; + use base qw/My::Schema::Result::User/; __PACKAGE__->table('dummy'); # currently must be called before anything else @@ -343,6 +332,10 @@ That creates the following SQL: WHERE artistid = me.artistid ) +=head3 EXPERIMENTAL + +Please note that subqueries are considered an experimental feature. + =head2 Predefined searches You can write your own L class by inheriting from it @@ -680,7 +673,7 @@ Employ the standard stringification technique by using the C module. To make an object stringify itself as a single column, use something -like this (replace C with the column/method of your choice): +like this (replace C with the column/method of your choice): use overload '""' => sub { shift->name}, fallback => 1; @@ -747,16 +740,16 @@ below: B - package DB::Schema; + package My::Schema; use base qw/DBIx::Class::Schema/; - __PACKAGE__->load_classes(qw/User/); + __PACKAGE__->load_namespaces; B - package DB::Schema::User; + package My::Schema::Result::User; use strict; use warnings; @@ -791,11 +784,11 @@ B } - package DB::Schema::User::Admin; + package My::Schema::Result::User::Admin; use strict; use warnings; - use base qw/DB::Schema::User/; + use base qw/My::Schema::Result::User/; sub hello { @@ -813,7 +806,7 @@ B test.pl use warnings; use strict; - use DB::Schema; + use My::Schema; my $user_data = { email => 'someguy@place.com', password => 'pass1', @@ -823,7 +816,7 @@ B test.pl password => 'pass2', admin => 1 }; - my $schema = DB::Schema->connection('dbi:Pg:dbname=test'); + my $schema = My::Schema->connection('dbi:Pg:dbname=test'); $schema->resultset('User')->create( $user_data ); $schema->resultset('User')->create( $admin_data ); @@ -861,11 +854,16 @@ To do this simply use L. Wasn't that easy? +Beware, changing the Result class using +L will replace any existing class +completely including any special components loaded using +load_components, eg L. + =head2 Get raw data for blindingly fast results If the L solution above is not fast enough for you, you can use a DBIx::Class to return values -exactly as they come out of the data base with none of the convenience methods +exactly as they come out of the database with none of the convenience methods wrapped round them. This is used like so: @@ -876,13 +874,13 @@ This is used like so: } You will need to map the array offsets to particular columns (you can -use the I