Method: Dynamoid::Document::ClassMethods#update

Defined in:
lib/dynamoid/document.rb

#update(hash_key, range_key_value = nil, attrs) ⇒ Dynamoid::Doument

Update document with provided values. Instantiates document and saves changes. Runs validations and callbacks.

Examples:

Update document

Post.update(101, read: true)

Parameters:

  • partition (Scalar value)

    key

  • sort (Scalar value)

    key, optional

  • attributes (Hash)

Returns:

  • (Dynamoid::Doument)

    updated document



159
160
161
162
163
# File 'lib/dynamoid/document.rb', line 159

def update(hash_key, range_key_value = nil, attrs)
  model = find(hash_key, range_key: range_key_value, consistent_read: true)
  model.update_attributes(attrs)
  model
end