X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FManual%2FCookbook.pod;h=5a9e75da7c1baca398b11b1b4dda0f222dd56127;hb=d6c20def67453a05c9f955bf6ee4258d80c01385;hp=8867e3fb16d4e16016626016d436cdb99df650ee;hpb=2552bd763b0bf0b646cf906c12e95aafb1ba0b7e;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Manual/Cookbook.pod b/lib/DBIx/Class/Manual/Cookbook.pod index 8867e3f..5a9e75d 100644 --- a/lib/DBIx/Class/Manual/Cookbook.pod +++ b/lib/DBIx/Class/Manual/Cookbook.pod @@ -336,7 +336,7 @@ B: You have to explicitly use '=' when doing an equality comparison. The following will B work: my $rs = $schema->resultset('CD')->search({ - artist_id => $inside_rs->get_column('id')->as_query, + artist_id => $inside_rs->get_column('id')->as_query, # does NOT work }); =head3 Support @@ -420,25 +420,24 @@ specification as you would any column: $rs->search({ 'YEAR(date_of_birth)' => 1979 }); -With quoting on, or for a more portable solution, use the C -attribute: +With quoting on, or for a more portable solution, use literal SQL values with +placeholders: - $rs->search({}, { where => \'YEAR(date_of_birth) = 1979' }); + $rs->search(\[ 'YEAR(date_of_birth)', [ dummy => 1979 ] ]); -=begin hidden - -(When the bind args ordering bug is fixed, this technique will be better -and can replace the one above.) - -With quoting on, or for a more portable solution, use the C and -C attributes: + # Equivalent SQL: + # SELECT * FROM employee WHERE YEAR(date_of_birth) = ? - $rs->search({}, { - where => \'YEAR(date_of_birth) = ?', - bind => [ 1979 ] + $rs->search({ + name => 'Bob', + -nest => \[ 'YEAR(date_of_birth)', [ dummy => 1979 ] ], }); -=end hidden + # Equivalent SQL: + # SELECT * FROM employee WHERE name = ? AND YEAR(date_of_birth) = ? + +See also L. =head1 JOINS AND PREFETCHING @@ -929,6 +928,9 @@ B test.pl ### The statement below will print print "I can do admin stuff\n" if $admin->can('do_admin_stuff'); +Alternatively you can use L that implements +exactly the above functionality. + =head2 Skip row object creation for faster results DBIx::Class is not built for speed, it's built for convenience and @@ -1069,7 +1071,7 @@ create the relationship. To order C<< $book->pages >> by descending page_number, create the relation as follows: - __PACKAGE__->has_many('pages' => 'Page', 'book', { order_by => \'page_number DESC'} ); + __PACKAGE__->has_many('pages' => 'Page', 'book', { order_by => { -desc => 'page_number'} } ); =head2 Filtering a relationship result set