X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FManual%2FCookbook.pod;h=9b9f9cefc02abe669cf426272be50dd779ac9794;hb=47d7b769c034e04989840b1efc2f5991518cff23;hp=56b325095b0723b3b99590a59dd1058f84d43b10;hpb=fb13a49f17a0e0a49638080a4bd826fb3702aebe;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Manual/Cookbook.pod b/lib/DBIx/Class/Manual/Cookbook.pod index 56b3250..9b9f9ce 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. @@ -604,7 +604,7 @@ C: # SELECT cd.*, artist.*, liner_notes.* FROM cd # JOIN artist ON cd.artist = artist.id # JOIN liner_notes ON cd.id = liner_notes.cd - # WHERE artist.name = 'Bob Marley' + # WHERE artist.name = 'Bob Marley' AND liner_notes.notes LIKE '%some text%' # ORDER BY artist.name =head2 Multi-step joins @@ -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] }, @@ -1941,8 +1941,9 @@ just looking for this. For example, say that you have three columns, C, C, and C. You would like to make changes to C and have C be automagically set to the value of C squared. -You can accomplish this by wrapping the C accessor with -L: +You can accomplish this by wrapping the C accessor with the C +method modifier, available through either L, +L or L modules): around number => sub { my ($orig, $self) = (shift, shift); @@ -1953,7 +1954,7 @@ L: } $self->$orig(@_); - } + }; Note that the hard work is done by the call to C<< $self->$orig >>, which redispatches your call to store_column in the superclass(es).