instance method
upsert
Ruby on Rails 7.0.10
Since v6.0.6 Last seen in v7.1.6Signature
upsert(attributes, on_duplicate: :update, returning: nil, unique_by: nil, record_timestamps: nil)
Updates or inserts (upserts) a single record into the database in a single SQL INSERT statement. It does not instantiate any models nor does it trigger Active Record callbacks or validations. Though passed values go through Active Record’s type casting and serialization.
See #upsert_all for documentation.
Parameters
-
attributesreq -
on_duplicatekey = :update -
returningkey = nil -
unique_bykey = nil -
record_timestampskey = nil
Source
# File activerecord/lib/active_record/persistence.rb, line 222
def upsert(attributes, on_duplicate: :update, returning: nil, unique_by: nil, record_timestamps: nil)
upsert_all([ attributes ], on_duplicate: on_duplicate, returning: returning, unique_by: unique_by, record_timestamps: record_timestamps)
end
Defined in activerecord/lib/active_record/persistence.rb line 222
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Persistence::ClassMethods