HEX
Server: Apache
System: Linux s198.coreserver.jp 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC 2025 x86_64
User: nagasaki (10062)
PHP: 7.1.33
Disabled: NONE
Upload Files
File: //usr/local/rvm/gems/ruby-2.5.9/doc/activerecord-6.1.4.1/ri/ActiveRecord/FinderMethods/find-i.ri
U:RDoc::AnyMethod[iI"	find:ETI"%ActiveRecord::FinderMethods#find;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph;	[I"rFind by id - This can either be a specific id (1), a list of ids (1, 5, 6), or an array of ids ([5, 6, 10]). ;TI"uIf one or more records cannot be found for the requested ids, then ActiveRecord::RecordNotFound will be raised. ;TI"XIf the primary key is an integer, find by id coerces its arguments by using +to_i+.;To:RDoc::Markup::BlankLineo:RDoc::Markup::Verbatim;	[I"=Person.find(1)          # returns the object for ID = 1
;TI"=Person.find("1")        # returns the object for ID = 1
;TI">Person.find("31-sarah") # returns the object for ID = 31
;TI"RPerson.find(1, 2, 6)    # returns an array for objects with IDs in (1, 2, 6)
;TI"PPerson.find([7, 17])    # returns an array for objects with IDs in (7, 17)
;TI"KPerson.find([1])        # returns an array for the object with ID = 1
;TI"HPerson.where("administrator = 1").order("created_on DESC").find(1)
;T:@format0o;
;	[	I"NNOTE: The returned records are in the same order as the ids you provide. ;TI"dIf you want the results to be sorted by database, you can use ActiveRecord::QueryMethods#where ;TI"Mmethod and provide an explicit ActiveRecord::QueryMethods#order option. ;TI"\But ActiveRecord::QueryMethods#where method doesn't raise ActiveRecord::RecordNotFound.;T@S:RDoc::Markup::Heading:
leveli	:	textI"Find with lock;T@o;
;	[
I"HExample for find with a lock: Imagine two concurrent transactions: ;TI"Reach will read <tt>person.visits == 2</tt>, add 1 to it, and save, resulting ;TI"Pin two saves of <tt>person.visits = 3</tt>. By locking the row, the second ;TI"Etransaction has to wait until the first is finished; we get the ;TI"*expected <tt>person.visits == 4</tt>.;T@o;;	[
I"Person.transaction do
;TI"*  person = Person.lock(true).find(1)
;TI"  person.visits += 1
;TI"  person.save!
;TI"	end
;T;
0S;;i	;I"Variations of #find;T@o;;	[I"0Person.where(name: 'Spartacus', rating: 4)
;TI"6# returns a chainable list (which can be empty).
;TI"
;TI"2Person.find_by(name: 'Spartacus', rating: 4)
;TI"&# returns the first item or nil.
;TI"
;TI"@Person.find_or_initialize_by(name: 'Spartacus', rating: 4)
;TI"s# returns the first item or returns a new instance (requires you call .save to persist against the database).
;TI"
;TI"<Person.find_or_create_by(name: 'Spartacus', rating: 4)
;TI"<# returns the first item or creates it and returns it.
;T;
0S;;i	;I"Alternatives for #find;T@o;;	[I"LPerson.where(name: 'Spartacus', rating: 4).exists?(conditions = :none)
;TI"S# returns a boolean indicating if any record with the given conditions exist.
;TI"
;TI"QPerson.where(name: 'Spartacus', rating: 4).select("field1, field2, field3")
;TI"M# returns a chainable list of instances with only the mentioned fields.
;TI"
;TI"4Person.where(name: 'Spartacus', rating: 4).ids
;TI" # returns an Array of ids.
;TI"
;TI"HPerson.where(name: 'Spartacus', rating: 4).pluck(:field1, :field2)
;TI"/# returns an Array of the required fields.;T;
0:
@fileI"1lib/active_record/relation/finder_methods.rb;T:0@omit_headings_from_table_of_contents_below000[I"(*args);T@NTI"FinderMethods;TcRDoc::NormalModule00