diff options
author | Damien Mathieu <42@dmathieu.com> | 2011-09-05 13:40:49 +0200 |
---|---|---|
committer | Damien Mathieu <42@dmathieu.com> | 2011-09-05 14:37:37 +0200 |
commit | 5f5527c726841cdefb82965a645d554767c5a6a9 (patch) | |
tree | 9988d58da2e27c67a6de9e01137f81b3dc9a6c9b /activerecord/lib | |
parent | 451cdd62ce54080d0a4944551fbc3f10cc34a42d (diff) | |
download | rails-5f5527c726841cdefb82965a645d554767c5a6a9.tar.gz rails-5f5527c726841cdefb82965a645d554767c5a6a9.tar.bz2 rails-5f5527c726841cdefb82965a645d554767c5a6a9.zip |
Use LIMIT sql word in last when it's possible
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/relation/finder_methods.rb | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index 2639c46709..83d650d3f4 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -134,7 +134,11 @@ module ActiveRecord def last(*args) if args.any? if args.first.kind_of?(Integer) || (loaded? && !args.first.kind_of?(Hash)) - to_a.last(*args) + if order_values.empty? && reorder_value.nil? + order("#{primary_key} DESC").limit(*args).reverse + else + to_a.last(*args) + end else apply_finder_options(args.first).last end |