模块:Mongoid::Persistable::Pullable
Overview
定义 $pull 和 $pullAll 操作的行为。
实例方法摘要折叠
-
#pull(pulls) ⇒ Document
从提供的数组中提取单个值。
-
# pull_all (pulls) ⇒ 文档
从提供的数组字段中提取多个值。
实例方法详细信息
#pull(pulls) ⇒ Document
注意:
如果发现重复值,则会将其全部拉取。
从提供的数组中提取单个值。
21 22 23 24 25 26 27 28 29 |
# File 'lib/mongoid/persistable/pullable.rb', line 21 def pull(pull) prepare_atomic_operation do |运维| process_atomic_operations(pull) do |字段, 值| (发送(字段) || []).删除(值) 运维[atomic_attribute_name(字段)] = 值 end { " $pull " => 运维 } end end |
#pull_all(pulls) ⇒ Document
从提供的数组字段中提取多个值。
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/mongoid/persistable/pullable.rb', line 39 def pull_all(pull) prepare_atomic_operation do |运维| process_atomic_operations(pull) do |字段, 值| 现有的 = 发送(字段) || [] 值.每{ |val| 现有的.删除(val) } 运维[atomic_attribute_name(字段)] = 值 end { " $pullAll " => 运维 } end end |