模块:Mongoid::Persistable::Renameable

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

Overview

定义 $rename 操作的行为。

实例方法摘要折叠

实例方法详细信息

# rename (renames) ⇒文档

注意:

这对于嵌入许多关联中的字段不起作用。

通过 $rename 将字段从一个值重命名为另一个值。

例子:

重命名字段。

document.rename(title: "salutation", name: "nombre")

参数:

  • renames (哈希)

    旧名称/新名称的重命名对。

返回:



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

def 改名(renames)
  prepare_atomic_operation do |运维|
    process_atomic_operations(renames) do |old_field, new_field|
      new_name = new_field.to_s
      if Executing_atomically?
        process_attribute new_name, 属性[old_field]
        process_attribute old_field, nil
      else
        属性[new_name] = 属性.删除(old_field)
      end
      运维[atomic_attribute_name(old_field)] = atomic_attribute_name(new_name)
    end
    { " $rename " => 运维 }
  end
end