Class: Mongoid::Persistence::Atomic::PullAll
- Defined in:
- lib/mongoid/persistence/atomic/pull_all.rb
Overview
This class provides the ability to perform an explicit $pullAll modification on a specific field.
Instance Attribute Summary
Attributes inherited from Operation
#document, #field, #options, #value
Instance Method Summary collapse
-
#persist ⇒ Object
Sends the atomic $pullAll operation to the database.
Methods inherited from Operation
Methods included from Safe
Constructor Details
This class inherits a constructor from Mongoid::Persistence::Atomic::Operation
Instance Method Details
#persist ⇒ Object
Sends the atomic $pullAll operation to the database.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/mongoid/persistence/atomic/pull_all.rb', line 18 def persist if document[field] values = document.send(field) values.delete_if { |val| value.include?(val) } values.tap do document.collection.update(document._selector, operation("$pullAll"), ) document.changes.delete(field.to_s) if document.persisted? end else return nil end end |