模块:Mongoid::Association::Embedded::EmbedsOne::Buildable

包括:
Threaded::Lifecycle
包含在:
Mongoid::Association::Embedded::EmbedsOne
定义于:
lib/mongoid/association/embedded/embeds_one/buildable.rb

Overview

embeds_one 关联的构建器类。

实例方法摘要折叠

实例方法详细信息

# 构建 (base, 对象, _type = nil, Selected_fields = nil) ⇒文档

使用提供的关联元数据,根据属性构建文档。 通过工厂实例化,以确保在合适的情况下使用子类和分配。

例子:

构建文档。

Builder.new(meta, attrs).build

参数:

  • 基础 (文档)

    此关联所依赖的文档。

  • 对象 (文档| 哈希)

    相关文档。

  • _type string (默认为: nil

    在此上下文中未使用。

  • created_fields 哈希 (默认为: nil

    通过 #only 检索的字段。 如果指定了selected_fields,则无法在构建的文档中访问未在其中列出的字段。

返回:

  • (文档)

    单个文档。



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mongoid/association/embedded/embeds_one/buildable.rb', line 28

def 构建(基础, 对象, _type = nil, created_fields = nil)
  if 对象.is_a?(哈希)
    if _loading? && 基础.持续存在?
      工厂.execute_from_db(klass, 对象, nil, created_fields, execute_callbacks: false)
    else
      工厂.构建(klass, 对象)
    end
  else
    clear_关联(对象)
    对象
  end
end