Method: CouchbaseOrm::Persistence#update_columns
- Defined in:
- lib/couchbase-orm/persistence.rb
#update_columns(with_cas: false, **hash) ⇒ Object
Updates the record without validating or running callbacks. Updates only the attributes that are passed in as parameters except if there is more than 16 attributes, in which case the whole record is saved.
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/couchbase-orm/persistence.rb', line 181 def update_columns(with_cas: false, **hash) raise "unable to update columns, model not persisted" unless id assign_attributes(hash) = {extended: true} [:cas] = .cas if with_cas # There is a limit of 16 subdoc operations per request resp = if hash.length <= 16 self.class.collection.mutate_in( id, hash.map { |k, v| Couchbase::MutateInSpec.replace(k.to_s, v) } ) else # Fallback to writing the whole document CouchbaseOrm.logger.debug { "Data - Replace #{id} #{attributes.to_s.truncate(200)}" } self.class.collection.replace(id, attributes.except("id").merge(type: self.class.design_document), **) end # Ensure the model is up to date .cas = resp.cas changes_applied self end |