method
first_or_initialize
v3.2.8 -
Show latest stable
- Class:
ActiveRecord::Relation
first_or_initialize(attributes = nil, options = {}, &block)public
Like first_or_create but calls new instead of create.
Expects arguments in the same format as Base.new.
1Note
Description
Selects the first record within a relation if it exists, otherwise creates a new record with the optional attributes.