instance method
find_one
Ruby on Rails 8.0.4
Since v3.0.20 PrivateSignature
find_one(id)
No documentation comment.
Parameters
-
idreq
Source
# File activerecord/lib/active_record/relation/finder_methods.rb, line 521
def find_one(id)
if ActiveRecord::Base === id
raise ArgumentError, <<-MSG.squish
You are passing an instance of ActiveRecord::Base to `find`.
Please pass the id of the object by calling `.id`.
MSG
end
relation = if model.composite_primary_key?
where(primary_key.zip(id).to_h)
else
where(primary_key => id)
end
record = relation.take
raise_record_not_found_exception!(id, 0, 1) unless record
record
end
Defined in activerecord/lib/active_record/relation/finder_methods.rb line 521
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::FinderMethods