method
find_some
v1.1.6 -
Show latest stable
- Class:
ActiveRecord::Base
find_some(ids, options)private
No documentation available.
# File activerecord/lib/active_record/base.rb, line 959
def find_some(ids, options)
conditions = " AND (#{sanitize_sql(options[:conditions])})" if options[:conditions]
ids_list = ids.map { |id| sanitize(id) }.join(',')
options.update :conditions => "#{table_name}.#{primary_key} IN (#{ids_list})#{conditions}"
result = find_every(options)
if result.size == ids.size
result
else
raise RecordNotFound, "Couldn't find all #{name.pluralize} with IDs (#{ids_list})#{conditions}"
end
end 3Notes
throws exception
when use use Model.find([1,2,3,4])
throws exception if no record exists with any of this ID
correction
I think what metavida meant was
User.find(1, 3) # ActiveRecord::RecordNotFound error not User.find_by_id(1, 3) # this will just return user 1
RecordNotFound when any id not found
As an example of bansalakhil's explanation.
User.find_by_id(1) #=> #<User:0x3d54a3c @attributes={"id"=>1}> User.find_by_id(2) #=> #<User:0x3d519a4 @attributes={"id"=>2}> User.find_by_id(3) #=> nil User.find_by_id(1, 2) #=> an Array with 2 User instances User.find_by_id(1, 3) #=> an ActiveRecord::RecordNotFound error