This project is archived and is in readonly mode.

#1430 ✓wontfix
Emilio Tagua

Allow limit option on find last to retrieve many recods

Reported by Emilio Tagua | November 21st, 2008 @ 09:47 PM | in 2.x

find(:last) (or just last) ignores the :limit option.

This was because of two reasons, returning only the last record matching the query and make use of find_initial.

Sometimes i need to query for the last X records created, for example: "Last 5 comments on this product..."

With this small patch you'll be able to do:

Product.find(:last, :limit => 5)

In order to retrieve those 5 products.

Comments and changes to this ticket

  • CancelProfileIsBroken

    CancelProfileIsBroken November 21st, 2008 @ 10:29 PM

    The syntax worries me a bit. It's not immediately obvious to me whether find(:last, :limit => 5) means "find the last five in the entire model" or "find a maximum of five instances and give me the last of those".

  • Emilio Tagua

    Emilio Tagua November 21st, 2008 @ 10:35 PM

    Hey Mike,

    The syntax is the same as for find(:all) and i guess you are not worried of doing find(:all, :limit =>5).

    Also find_initial (or first) is just a find(:all) (or find_every) with :limit => 1.

  • DHH

    DHH November 23rd, 2008 @ 05:37 PM

    • State changed from “new” to “wontfix”

    Gotta say that I'm not a fan. find(:last) is a mirror of find(:first), not find(:all).

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>