X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FManual%2FFAQ.pod;h=2ff72ee489755ed69505edc18daf149b7540821d;hb=88262f96056323dd426285bd45fbe385168cd0d3;hp=a76cccaf1c52fa573a325828038abc565b7f784f;hpb=75e75a9f4b3bcd73696a575e72f8a33b985823fd;p=dbsrgits%2FDBIx-Class-Historic.git 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