[Bast-commits] r7041 - DBIx-Class/0.08/trunk/lib/DBIx/Class/Manual

dandv at dev.catalyst.perl.org dandv at dev.catalyst.perl.org
Mon Jul 13 21:48:18 GMT 2009


Author: dandv
Date: 2009-07-13 21:48:18 +0000 (Mon, 13 Jul 2009)
New Revision: 7041

Modified:
   DBIx-Class/0.08/trunk/lib/DBIx/Class/Manual/FAQ.pod
Log:
Favored using ->single to get the topmost result over less readable ->slice(0)

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Manual/FAQ.pod
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Manual/FAQ.pod	2009-07-13 21:18:11 UTC (rev 7040)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Manual/FAQ.pod	2009-07-13 21:48:18 UTC (rev 7041)
@@ -324,22 +324,17 @@
 
 =item .. fetch a single (or topmost) row?
 
-Sometimes you many only want a single record back from a search. A quick
-way to get that single row is to first run your search as usual:
+See L<DBIx::Class::Manual::Cookbook/Retrieve_one_and_only_one_row_from_a_resultset>.
 
-  ->search->(undef, { order_by => "id DESC" })
+A less readable way is to ask a regular search to return 1 row, using
+L<DBIx::Class::ResultSet/slice>:
 
-Then call L<DBIx::Class::ResultSet/slice> and ask it only to return 1 row:
-
-  ->slice(0)
-
-These two calls can be combined into a single statement:
-
   ->search->(undef, { order_by => "id DESC" })->slice(0)
 
-Why slice instead of L<DBIx::Class::ResultSet/first> or L<DBIx::Class::ResultSet/single>?
-If supported by the database, slice will use LIMIT/OFFSET to hint to the database that we
-really only need one row. This can result in a significant speed improvement.
+which (if supported by the database) will use LIMIT/OFFSET to hint to the
+database that we really only need one row. This can result in a significant
+speed improvement. The method using L<DBIx::Class::ResultSet/single> mentioned
+in the cookbook can do the same if you pass a C<rows> attribute to the search.
 
 =item .. refresh a row from storage?
 




More information about the Bast-commits mailing list