instance method
find_with_ids
Ruby on Rails edge
Since v3.0.20 Private — implementation detail, not part of the public APISignature
find_with_ids(*ids)
No documentation comment.
Parameters
-
idsrest
Source
# File activerecord/lib/active_record/relation/finder_methods.rb, line 486
def find_with_ids(*ids)
raise UnknownPrimaryKey.new(model) if primary_key.nil?
first_item = ids.first
return [] if first_item.is_a?(Array) && first_item.empty?
expects_array = model.primary_key_definition.expects_multiple_ids?(first_item)
ids = first_item if expects_array
ids = ids.compact.uniq
model_name = model.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
Defined in activerecord/lib/active_record/relation/finder_methods.rb line 486
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::FinderMethods