模块:Mongoid::Persistable::Minable

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

Overview

定义将一个或多个字段设置为当前值或给定值中较小值的行为。

实例方法摘要折叠

实例方法详细信息

# set_min (fields) ⇒文档也称为: clip_upper_bound

将给定的一个或多个字段设置为当前值或给定值中较小的值。

例子:

将字段设置为不超过100 。

document.min(field: 100)

参数:

  • 字段 ( Hash<Symbol | string , Comparable> )

    要设立的字段,以及相应的最大值。

返回:



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/mongoid/persistable/minable.rb', line 22

def set_min(字段)
  prepare_atomic_operation do |运维|
    process_atomic_operations(字段) do |字段, |
      current_value = 属性[字段]
      if  < current_value
        process_attribute 字段, 
        运维[atomic_attribute_name(字段)] = 
      end
    end
    { "$min" => 运维 } 除非 运维.空?
  end
end