instance method upsert

Ruby on Rails 7.0.10

Since v6.0.6 Last seen in v7.1.6

Available in: v6.0.6 v6.1.7.10 v7.0.10 v7.1.6

Signature

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

attributes req
on_duplicate key = :update
returning key = nil
unique_by key = nil
record_timestamps key = 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

Type at least 2 characters to search.

↑↓ navigate · open · esc close