提交 489166e1 编写于 作者: M Marcelo Silveira

Document `last`, check for primary key on default order and use quoted table and column names

上级 07e5301e
......@@ -87,6 +87,9 @@ def first!
first or raise RecordNotFound
end
# Find the last record (or last N records if a parameter is supplied).
# If no order is defined it will order by primary key.
#
# Examples:
#
# Person.last # returns the last object fetched by SELECT * FROM people
......@@ -94,8 +97,8 @@ def first!
# Person.order("created_on DESC").offset(5).last
def last(limit = nil)
if limit
if order_values.empty?
order("#{primary_key} DESC").limit(limit).reverse
if order_values.empty? && primary_key
order("#{quoted_table_name}.#{quoted_primary_key} DESC").limit(limit).reverse
else
to_a.last(limit)
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册