From 859a91b59a7b58198e5fdb382fb6e610b2738034 Mon Sep 17 00:00:00 2001 From: Reg Braithwaite Date: Thu, 12 Apr 2012 22:24:21 -0400 Subject: [PATCH] Documents that ActiveRecord's find by id uses to_i to coerce its arguments to integers --- activerecord/lib/active_record/relation/finder_methods.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index 74f8e30404..af89493d9d 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -6,7 +6,8 @@ module FinderMethods # Find operates with four different retrieval approaches: # # * Find by id - This can either be a specific id (1), a list of ids (1, 5, 6), or an array of ids ([5, 6, 10]). - # If no record can be found for all of the listed ids, then RecordNotFound will be raised. + # If no record can be found for all of the listed ids, then RecordNotFound will be raised. Find by id coerces + # its arguments to integers using #to_i. # * Find first - This will return the first record matched by the options used. These options can either be specific # conditions or merely an order. If no record can be matched, +nil+ is returned. Use # Model.find(:first, *args) or its shortcut Model.first(*args). @@ -51,6 +52,7 @@ module FinderMethods # # # find by id # Person.find(1) # returns the object for ID = 1 + # Person.find("1") # returns the object for ID = 1 # Person.find(1, 2, 6) # returns an array for objects with IDs in (1, 2, 6) # Person.find([7, 17]) # returns an array for objects with IDs in (7, 17) # Person.find([1]) # returns an array for the object with ID = 1 -- GitLab