module ActiveRecord::FinderMethods
def last(limit = nil)
and not:
[#
Take note that in that last case, the results are sorted in ascending order:
Person.last(3) # returns the last three objects fetched by SELECT * FROM people.
Person.order("created_on DESC").offset(5).last
Person.where(["user_name = ?", user_name]).last
Person.last # returns the last object fetched by SELECT * FROM people
If no order is defined it will order by primary key.
Find the last record (or last N records if a parameter is supplied).
def last(limit = nil) if limit if order_values.empty? && primary_key order(arel_table[primary_key].desc).limit(limit).reverse else to_a.last(limit) end else find_last end end