Method: Dynamoid::Persistence#update!
- Defined in:
- lib/dynamoid/persistence.rb
#update!(conditions = {}, &block) ⇒ Object
update!() will increment the lock_version if the table has the column, but will not check it. Thus, a concurrent save will never cause an update! to fail, but an update! may cause a concurrent save to fail.
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/dynamoid/persistence.rb', line 305 def update!(conditions = {}, &block) run_callbacks(:update) do = range_key ? {range_key: dump_field(self.read_attribute(range_key), self.class.attributes[range_key])} : {} begin new_attrs = Dynamoid.adapter.update_item(self.class.table_name, self.hash_key, .merge(conditions: conditions)) do |t| if(self.class.attributes[:lock_version]) t.add(lock_version: 1) end yield t end load(new_attrs) rescue Dynamoid::Errors::ConditionalCheckFailedException raise Dynamoid::Errors::StaleObjectError.new(self, 'update') end end end |