Method: CouchbaseOrm::Persistence#_update_record

Defined in:
lib/couchbase-orm/persistence.rb

#_update_record(*_args, with_cas: false, **options) ⇒ Object



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/couchbase-orm/persistence.rb', line 235

def _update_record(*_args, with_cas: false, **options)
    return false unless perform_validations(:update, options)
    return true unless changed? || self.class.attribute_types.any? { |_, type| type.is_a?(CouchbaseOrm::Types::Nested) || type.is_a?(CouchbaseOrm::Types::Array)  }

    run_callbacks :update do
        run_callbacks :save do
            options[:cas] = .cas if with_cas
            CouchbaseOrm.logger.debug { "_update_record - replace #{id} #{serialized_attributes.to_s.truncate(200)}" }
            if options[:transcoder].nil?
                options[:transcoder] = CouchbaseOrm::JsonTranscoder.new(json_validation_config: self.class.json_validation_config)
            end
            resp = self.class.collection.replace(id, serialized_attributes.except("id").merge(type: self.class.design_document), Couchbase::Options::Replace.new(**options))

            # Ensure the model is up to date
            .cas = resp.cas

            changes_applied
            true
        end
    end
end