From: Robert Krimen Date: Wed, 14 Feb 2007 08:39:26 +0000 (+0000) Subject: Added how to '.. fetch a single (or topmost) row?' to the FAQ X-Git-Tag: v0.08010~180 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2486df86df6c28d8305ae777acdac19ba6faebcf;p=dbsrgits%2FDBIx-Class.git Added how to '.. fetch a single (or topmost) row?' to the FAQ --- diff --git a/lib/DBIx/Class/Manual/FAQ.pod b/lib/DBIx/Class/Manual/FAQ.pod index a76ccca..2ff72ee 100644 --- a/lib/DBIx/Class/Manual/FAQ.pod +++ b/lib/DBIx/Class/Manual/FAQ.pod @@ -266,6 +266,25 @@ fetches the real value and does the formatting you want. 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: + + ->search->(undef, { order_by => "id DESC" }) + +Then call L and ask it only to return 1 row: + + ->slice(0,1) + +These two calls can be combined into a single statement: + + ->search->(undef, { order_by => "id DESC" })->slice(0,1) + +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. + =back =head2 Inserting and updating data