Module: Mongoid::Locking::Persistable::Updatable

Included in:
Mongoid::Locking::Persistable
Defined in:
lib/mongoid/locking/persistable/updatable.rb

Overview

:nodoc:

Since:

  • 0.1.0

Instance Method Summary collapse

Instance Method Details

#update_document(options = {}) ⇒ Object

Overrides the default Mongoid::Persistable::Updatable#update_document to:

  • include the lock_version in the atomic selector

  • increment the lock_version in the atomic updates

Since:

  • 0.1.0



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/mongoid/locking/persistable/updatable.rb', line 9

def update_document(options = {})
  prepare_update(options) do
    updates, conflicts = init_atomic_updates
    unless updates.empty?
      coll = collection(_root)
      selector = atomic_selector
      _update_one_locked(coll, selector, updates)
      conflicts.each_pair do |key, value|
        coll.find(selector).update_one(positionally(selector, { key => value }), session: _session)
      end
    end
  end
end