method
find_with_ids
v7.1.3.4 -
Show latest stable
- Class:
ActiveRecord::FinderMethods
find_with_ids(*ids)private
No documentation available.
# File activerecord/lib/active_record/relation/finder_methods.rb, line 477
def find_with_ids(*ids)
raise UnknownPrimaryKey.new(@klass) if primary_key.nil?
expects_array = if klass.composite_primary_key?
ids.first.first.is_a?(Array)
else
ids.first.is_a?(Array)
end
return [] if expects_array && ids.first.empty?
ids = ids.first if expects_array
ids = ids.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
end