Method: Dynamoid::Persistence#delete

Defined in:
lib/dynamoid/persistence.rb

#deleteObject

Delete this object from the datastore.

Since:

  • 0.2.0



348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/dynamoid/persistence.rb', line 348

def delete
  options = range_key ? {range_key: dump_field(self.read_attribute(range_key), self.class.attributes[range_key])} : {}

  # Add an optimistic locking check if the lock_version column exists
  if(self.class.attributes[:lock_version])
    conditions = {if: {}}
    conditions[:if][:lock_version] =
      if changes[:lock_version].nil?
        self.lock_version
      else
        changes[:lock_version][0]
      end
    options[:conditions] = conditions
  end
  Dynamoid.adapter.delete(self.class.table_name, self.hash_key, options)
rescue Dynamoid::Errors::ConditionalCheckFailedException
  raise Dynamoid::Errors::StaleObjectError.new(self, 'delete')
end