aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/finder_methods.rb
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2010-04-04 17:34:23 +0100
committerAndrew White <andyw@pixeltrix.co.uk>2010-04-04 17:34:23 +0100
commit00884a59013a658082dab41da5ff41add31b8c43 (patch)
tree666b862b08b04c7a3727ee22b2cd1a2561af4e52 /activerecord/lib/active_record/relation/finder_methods.rb
parent48b2451142355b22de5f8130b3debdd4e53e2ba2 (diff)
parent7d7e0627a0490b6b4ddb0ee5429264ccd46f1245 (diff)
downloadrails-00884a59013a658082dab41da5ff41add31b8c43.tar.gz
rails-00884a59013a658082dab41da5ff41add31b8c43.tar.bz2
rails-00884a59013a658082dab41da5ff41add31b8c43.zip
Merge branch 'master' of github.com:lifo/docrails
Diffstat (limited to 'activerecord/lib/active_record/relation/finder_methods.rb')
-rw-r--r--activerecord/lib/active_record/relation/finder_methods.rb20
1 files changed, 18 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index 37aaac0894..a26f1c0ac8 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -106,13 +106,29 @@ module ActiveRecord
# A convenience wrapper for <tt>find(:first, *args)</tt>. You can pass in all the
# same arguments to this method as you can to <tt>find(:first)</tt>.
def first(*args)
- args.any? ? apply_finder_options(args.first).first : find_first
+ if args.any?
+ if args.first.kind_of?(Integer) || (loaded? && !args.first.kind_of?(Hash))
+ to_a.first(*args)
+ else
+ apply_finder_options(args.first).first
+ end
+ else
+ find_first
+ end
end
# A convenience wrapper for <tt>find(:last, *args)</tt>. You can pass in all the
# same arguments to this method as you can to <tt>find(:last)</tt>.
def last(*args)
- args.any? ? apply_finder_options(args.first).last : find_last
+ if args.any?
+ if args.first.kind_of?(Integer) || (loaded? && !args.first.kind_of?(Hash))
+ to_a.last(*args)
+ else
+ apply_finder_options(args.first).last
+ end
+ else
+ find_last
+ end
end
# A convenience wrapper for <tt>find(:all, *args)</tt>. You can pass in all the