Module: Mongoid::Persistable::Pullable
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
ActiveSupport::Concern
|
|
Defined in: | lib/mongoid/persistable/pullable.rb |
Overview
Defines behavior for $pull and $pullAll operations.
Instance Method Summary
-
#pull(pulls) ⇒ Document
Pull single values from the provided arrays.
-
#pull_all(pulls) ⇒ Document
Pull multiple values from the provided array fields.
Instance Method Details
#pull(pulls) ⇒ Document
Note:
If duplicate values are found they will all be pulled.
Pull single values from the provided arrays.
# File 'lib/mongoid/persistable/pullable.rb', line 21
def pull(pulls) prepare_atomic_operation do |ops| process_atomic_operations(pulls) do |field, value| (send(field) || []).delete(value) ops[atomic_attribute_name(field)] = value end { "$pull" => ops } end end
#pull_all(pulls) ⇒ Document
Pull multiple values from the provided array fields.
# File 'lib/mongoid/persistable/pullable.rb', line 39
def pull_all(pulls) prepare_atomic_operation do |ops| process_atomic_operations(pulls) do |field, value| existing = send(field) || [] value.each{ |val| existing.delete(val) } ops[atomic_attribute_name(field)] = value end { "$pullAll" => ops } end end