模块:Mongoid::Persistable::Pullable

扩展方式:
ActiveSupport::Concern
包含在:
Mongoid::Persistable
定义于:
lib/mongoid/persistable/pullable.rb

Overview

定义 $pull 和 $pullAll 操作的行为。

实例方法摘要折叠

实例方法详细信息

#pull(pulls) ⇒ Document

注意:

如果发现重复值,则会将其全部拉取。

从提供的数组中提取单个值。

例子:

从大量中提取一个值。

document.pull(names: "Jeff", levels: 5)

参数:

  • pull (哈希)

    字段/值拉取对。

返回:



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

从提供的数组字段中提取多个值。

例子:

从数组中提取值。

document.pull_all(names: [ "Jeff", "Bob" ], levels: [ 5, 6 ])

参数:

  • pull (哈希)

    拉取所有操作。

返回:



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