method
find_with_ids
v5.2.3 -
Show latest stable
- Class:
ActiveRecord::FinderMethods
find_with_ids(*ids)private
No documentation available.
# File activerecord/lib/active_record/relation/finder_methods.rb, line 420
def find_with_ids(*ids)
raise UnknownPrimaryKey.new(@klass) if primary_key.nil?
expects_array = ids.first.kind_of?(Array)
return [] if expects_array && ids.first.empty?
ids = ids.flatten.compact.uniq
model_name = @klass.name
case ids.size
when 0
error_message = "Couldn't find #{model_name} without an ID"
raise RecordNotFound.new(error_message, model_name, primary_key)
when 1
result = find_one(ids.first)
expects_array ? [ result ] : result
else
find_some(ids)
end
rescue ::RangeError
error_message = "Couldn't find #{model_name} with an out of range ID"
raise RecordNotFound.new(error_message, model_name, primary_key, ids)
end