X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FManual%2FCookbook.pod;h=0cb560bdf9b9f84bf982e706e062f5d99a4b2060;hb=30681c23187d5f13d57eda0c97dda1be5fb291d1;hp=21d720e10e2360e8ce7451ea394f3d56238ea836;hpb=5f7ff3f01b9b1b34137d99ed2e9e4d8247d5bcd4;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Manual/Cookbook.pod b/lib/DBIx/Class/Manual/Cookbook.pod index 21d720e..0cb560b 100644 --- a/lib/DBIx/Class/Manual/Cookbook.pod +++ b/lib/DBIx/Class/Manual/Cookbook.pod @@ -421,26 +421,26 @@ you create an index on the return value of the function in question.) However, it can be accomplished with C when necessary by resorting to literal SQL: - $rs->search(\[ 'YEAR(date_of_birth) = ?', [ plain_value => 1979 ] ]); + $rs->search( + \[ 'YEAR(date_of_birth) = ?', 1979 ] + ); # Equivalent SQL: # SELECT * FROM employee WHERE YEAR(date_of_birth) = ? +To include the function as part of a larger search, use the '-and' keyword +to collect the search conditions: + $rs->search({ -and => [ name => 'Bob', - \[ 'YEAR(date_of_birth) = ?', [ plain_value => 1979 ] ], + \[ 'YEAR(date_of_birth) = ?', 1979 ] ]}); # Equivalent SQL: # SELECT * FROM employee WHERE name = ? AND YEAR(date_of_birth) = ? -Note: the C string in the C<< [ plain_value => 1979 ] >> part -should be either the same as the name of the column (do this if the type of the -return value of the function is the same as the type of the column) or in the -case of a function it's currently treated as a dummy string (it is a good idea -to use C or something similar to convey intent). The value is -currently only significant when handling special column types (BLOBs, arrays, -etc.), but this may change in the future. +Note: the syntax for specifying the bind value's datatype and value is +explained in L. See also L. @@ -840,7 +840,7 @@ AKA multi-class object inflation from one table L classes are proxy classes, therefore some different techniques need to be employed for more than basic subclassing. In this example we have a single user table that carries a boolean bit -for admin. We would like like to give the admin users +for admin. We would like to give the admin users objects (L) the same methods as a regular user but also special admin only methods. It doesn't make sense to create two separate proxy-class files for this. We would be copying all the user @@ -1108,7 +1108,7 @@ as follows: =head2 Filtering a relationship result set -If you want to get a filtered result set, you can just add add to $attr as follows: +If you want to get a filtered result set, you can just add to $attr as follows: __PACKAGE__->has_many('pages' => 'Page', 'book', { where => { scrap => 0 } } ); @@ -1163,14 +1163,14 @@ as each other and your connecting database user has the proper permissions to th To accomplish this one only needs to specify the DB schema name in the table declaration, like so... - package MyDatabase::Main::Artist; + package MyApp::Schema::Result::Artist; use base qw/DBIx::Class::Core/; __PACKAGE__->table('database1.artist'); # will use "database1.artist" in FROM clause __PACKAGE__->add_columns(qw/ artist_id name /); __PACKAGE__->set_primary_key('artist_id'); - __PACKAGE__->has_many('cds' => 'MyDatabase::Main::Cd'); + __PACKAGE__->has_many('cds' => 'MyApp::Schema::Result::Cd'); 1; @@ -1183,10 +1183,10 @@ of your application to support a change lifecycle (e.g. DEV, TEST, PROD) and the DB schemas are named based on the environment (e.g. database1_dev). However, one can dynamically "map" to the proper DB schema by overriding the -L method in your Schema class and +L method in your Schema class and building a renaming facility, like so: - package MyDatabase::Schema; + package MyApp::Schema; use Moose; extends 'DBIx::Class::Schema'; @@ -1223,16 +1223,16 @@ building a renaming facility, like so: 1; -By overridding the L +By overriding the L method and extracting a custom option from the provided \%attr hashref one can then simply iterate over all the Schema's ResultSources, renaming them as needed. To use this facility, simply add or modify the \%attr hashref that is passed to -L, as follows: +L, as follows: my $schema - = MyDatabase::Schema->connect( + = MyApp::Schema->connect( $dsn, $user, $pass, @@ -1357,9 +1357,9 @@ row. }); } catch { $exception = $_; - } + }; - if ($caught) { + if ($exception) { # There was an error while handling the $job. Rollback all changes # since the transaction started, including the already committed # ('released') savepoints. There will be neither a new $job nor any @@ -1737,7 +1737,7 @@ methods: numbers => [1, 2, 3] }); - $row->update( + $result->update( { numbers => [1, 2, 3] }, @@ -2190,7 +2190,7 @@ L programs can have a significant startup delay as the ORM loads all the relevant classes. This section examines techniques for reducing the startup delay. -These tips are are listed in order of decreasing effectiveness - so the +These tips are listed in order of decreasing effectiveness - so the first tip, if applicable, should have the greatest effect on your application.