lib/mongoid/persistable.rb in mongoid-5.0.2 vs lib/mongoid/persistable.rb in mongoid-5.1.0
- old
+ new
@@ -53,11 +53,11 @@
# @return [ true, false ] If the operation succeeded.
#
# @since 4.0.0
def atomically
begin
- @atomic_updates_to_execute = {}
+ @atomic_updates_to_execute = @atomic_updates_to_execute || {}
yield(self) if block_given?
persist_atomic_operations(@atomic_updates_to_execute)
true
ensure
@atomic_updates_to_execute = nil
@@ -205,10 +205,10 @@
#
# @param [ Hash ] operations The atomic operations.
#
# @since 4.0.0
def persist_atomic_operations(operations)
- if persisted?
+ if persisted? && operations
selector = atomic_selector
_root.collection.find(selector).update_one(positionally(selector, operations))
end
end
end