类:Mongoid::Association::Embedded::EmbedsOne::Proxy

继承:
one
  • 对象
显示全部
定义于:
lib/mongoid/association/embedded/embeds_one/proxy.rb

Overview

embeds_one 关联的透明代理。 对父文档调用关联 getter 方法时,会返回此类的实例。 该类继承自 Mongoid::Association::Proxy ,并将其大多数方法转发到关联的目标,即子文档。

常量摘要折叠

VALID_OPTIONS =

定义此关联时的有效选项。

返回:

  • ( Array<Symbol> )

    定义此关联时允许的选项。

%i[
  autobuild
  作为
  cascade_callbacks
  循环
  store_as
].冻结

Proxy继承的常量

Proxy::KEEPER_METHODS

实例属性摘要

Proxy继承的属性

#_association#_base#_target

类方法摘要折叠

实例方法摘要折叠

One继承的方法

#__evolve_object_id__#clear#in_memory#respond_to?

Proxy继承的方法

apply_ordering#extend_proxies#klass#reset_unloaded#substitutable

包含在封送处理中的方法

#marshal_dump#marshal_load

构造函数详情

#initialize (base, target,association) ⇒代理

实例化新的 embeds_one 关联。

例子:

创建新代理。

One.new(person, name, association)

参数:



33
34
35
36
37
38
39
40
41
42
# File 'lib/mongoid/association/embedded/embeds_one/proxy.rb', line 33

def 初始化(基础, 目标, 关联)
   do
    characterize_one(_target)
    bind_one
    characterize_one(_target)
    update_attributes_hash(_target)
    _target.保存 if 持久化?
    _base._reset_memoized_descendants!
  end
end

类方法详细信息

Eager_Loader (associations, Docs ) ⇒ Mongoid::Association::Embedded::Eager

返回此关联的热切加载器。

参数:

返回:



190
191
192
# File 'lib/mongoid/association/embedded/embeds_one/proxy.rb', line 190

def Eager_Loader(关联, docs)
  Eager.new(关联, docs)
end

嵌入式?true

如果关联为嵌入式关联,则返回 true。 在这种情况下始终为 true。

例子:

此关联是否为嵌入式关联?

Association::Embedded::EmbedsOne.embedded?

返回:

  • ( true )

    true。



201
202
203
# File 'lib/mongoid/association/embedded/embeds_one/proxy.rb', line 201

def 嵌入式?
  true
end

路径(文档) ⇒ Mongoid::Atomic::Paths::Embedded::One

获取所提供文档的路径计算器。

例子:

获取路径计算器。

Proxy.path(document)

参数:

  • 文档 (文档)

    要计算的文档。

返回:



214
215
216
# File 'lib/mongoid/association/embedded/embeds_one/proxy.rb', line 214

def 路径(文档)
  Mongoid::原子性::路径::Embedded::one.new(文档)
end

实例方法详细信息

#替换(replacement) ⇒文档| nil

用提供的目标文档替换关联中的现有文档。

例子:

替换新文档。

person.name.substitute(new_name)

参数:

  • 替换 (文档| 哈希)

    用于替换目标的文档。

返回:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/mongoid/association/embedded/embeds_one/proxy.rb', line 53

def 替换(替换)
  return self if 替换 == self

  if _Assigning?
    _base.add_atomic_unset(_target) 除非 替换
  else
    update_target_when_not_assing(替换)
  end

  unbind_one

  return nil if replace_with_nil_document(替换)

  replace_with(替换)

  self
end