类:Mongoid::Association::Embedded::EmbeddedIn::Proxy

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

Overview

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

常量摘要

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) ⇒ In

实例化一个新的 embedded_in 关联。

例子:

创建新关联。

Association::Embedded::EmbeddedIn.new(person, address, association)

参数:



24
25
26
27
28
29
# File 'lib/mongoid/association/embedded/embedded_in/proxy.rb', line 24

def 初始化(基础, 目标, 关联)
   do
    characterize_one(_target)
    bind_one
  end
end

类方法详细信息

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

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

参数:

返回:



95
96
97
# File 'lib/mongoid/association/embedded/embedded_in/proxy.rb', line 95

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

嵌入式?true

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

例子:

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

Association::Embedded::EmbeddedIn.embedded?

返回:

  • ( true )

    true。



106
107
108
# File 'lib/mongoid/association/embedded/embedded_in/proxy.rb', line 106

def 嵌入式?
  true
end

路径(文档) ⇒

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

例子:

获取路径计算器。

Proxy.path(document)

参数:

  • 文档 (文档)

    要计算的文档。

返回:

  • ( Root )

    根原子路径计算器。



118
119
120
# File 'lib/mongoid/association/embedded/embedded_in/proxy.rb', line 118

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

实例方法详细信息

#替换(replacement) ⇒文档| nil

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

例子:

替换新文档。

person.name.substitute(new_name)

参数:

  • 替换 (文档| 哈希)

    用于替换目标的文档。

返回:



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/mongoid/association/embedded/embedded_in/proxy.rb', line 40

def 替换(替换)
  unbind_one
  除非 替换
    _base.删除 if 持久化?
    return nil
  end
  _base.new_record = true
  替换 = 工厂.构建(klass, 替换) if 替换.is_a?(::哈希)
  self._target = 替换
  bind_one
  self
end