From: Dan Dascalescu Date: Mon, 13 Jul 2009 21:48:18 +0000 (+0000) Subject: Favored using ->single to get the topmost result over less readable ->slice(0) X-Git-Tag: v0.08109~82 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=38fc8cf6b92d08efc4f80807895fdcad804d163a;p=dbsrgits%2FDBIx-Class.git Favored using ->single to get the topmost result over less readable ->slice(0) --- diff --git a/lib/DBIx/Class/Manual/FAQ.pod b/lib/DBIx/Class/Manual/FAQ.pod index 114583d..d0f6634 100644 --- a/lib/DBIx/Class/Manual/FAQ.pod +++ b/lib/DBIx/Class/Manual/FAQ.pod @@ -324,22 +324,17 @@ See the Cookbook for more details. =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. - ->search->(undef, { order_by => "id DESC" }) - -Then call L and ask it only to return 1 row: - - ->slice(0) - -These two calls can be combined into a single statement: +A less readable way is to ask a regular search to return 1 row, using +L: ->search->(undef, { order_by => "id DESC" })->slice(0) -Why slice instead of L or L? -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 mentioned +in the cookbook can do the same if you pass a C attribute to the search. =item .. refresh a row from storage?