lib/dynamoid/persistence/save.rb in dynamoid-3.9.0 vs lib/dynamoid/persistence/save.rb in dynamoid-3.10.0
- old
+ new
@@ -66,17 +66,15 @@
conditions[:unless_exists] << @model.range_key
end
end
# Add an optimistic locking check if the lock_version column exists
- if @model.class.attributes[:lock_version]
- # Uses the original lock_version value from Dirty API
- # in case user changed 'lock_version' manually
- if @model.changes[:lock_version][0]
- conditions[:if] ||= {}
- conditions[:if][:lock_version] = @model.changes[:lock_version][0]
- end
+ # Uses the original lock_version value from Dirty API
+ # in case user changed 'lock_version' manually
+ if @model.class.attributes[:lock_version] && (@model.changes[:lock_version][0])
+ conditions[:if] ||= {}
+ conditions[:if][:lock_version] = @model.changes[:lock_version][0]
end
conditions
end
@@ -87,20 +85,18 @@
value_dumped = Dumping.dump_field(@model.range_value, @model.class.attributes[@model.class.range_key])
options[:range_key] = value_dumped
end
conditions = {}
- conditions[:if_exists] ||= {}
- conditions[:if_exists][@model.class.hash_key] = @model.hash_key
+ conditions[:if] ||= {}
+ conditions[:if][@model.class.hash_key] = @model.hash_key
# Add an optimistic locking check if the lock_version column exists
- if @model.class.attributes[:lock_version]
- # Uses the original lock_version value from Dirty API
- # in case user changed 'lock_version' manually
- if @model.changes[:lock_version][0]
- conditions[:if] ||= {}
- conditions[:if][:lock_version] = @model.changes[:lock_version][0]
- end
+ # Uses the original lock_version value from Dirty API
+ # in case user changed 'lock_version' manually
+ if @model.class.attributes[:lock_version] && (@model.changes[:lock_version][0])
+ conditions[:if] ||= {}
+ conditions[:if][:lock_version] = @model.changes[:lock_version][0]
end
options[:conditions] = conditions
options