diff options
author | Marcelo Silveira <marcelo@mhfs.com.br> | 2012-04-26 20:10:10 -0300 |
---|---|---|
committer | Marcelo Silveira <marcelo@mhfs.com.br> | 2012-05-02 21:25:40 -0300 |
commit | 489166e114ba3af54b1f2081027cd44078d32bbc (patch) | |
tree | 65e6e638d583a7bec2aace771f645799c0eb6c89 /activerecord/lib | |
parent | 07e5301e697d6a02ed3c079aba07c261d53c1846 (diff) | |
download | rails-489166e114ba3af54b1f2081027cd44078d32bbc.tar.gz rails-489166e114ba3af54b1f2081027cd44078d32bbc.tar.bz2 rails-489166e114ba3af54b1f2081027cd44078d32bbc.zip |
Document `last`, check for primary key on default order and use quoted table and column names
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/relation/finder_methods.rb | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index 9fd8b49ffb..4a41f1ea8b 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -87,6 +87,9 @@ module ActiveRecord 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 @@ module ActiveRecord # 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 |