类:Mongoid::Association::Referenced::BelongsTo::Proxy

继承:
one
  • 对象
显示全部
包括:
可演进
定义于:
lib/mongoid/association/referenced/belongs_to/proxy.rb

Overview

Belong_to 关联的透明代理。 对主题文档调用关联 getter 方法时,将返回此类的实例。 该类继承自 Mongoid::Association::Proxy,并将其大部分方法转发到关联的目标,即必须加载的对方集合上的文档。

常量摘要

Proxy继承的常量

Proxy::KEEPER_METHODS

实例属性摘要

Proxy继承的属性

#_association#_base#_target

类方法摘要折叠

实例方法摘要折叠

包含在Evolvable中的方法

#__evolve_object_id__

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) ⇒代理

实例化一个新的 belongs_to 关联代理。

例子:

创建新代理。

Association::BelongsTo::Proxy.new(game, person, association)

参数:



26
27
28
29
30
31
# File 'lib/mongoid/association/referenced/belongs_to/proxy.rb', line 26

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

类方法详细信息

Eager_Loader (association, Docs ) ⇒ Mongoid::Association::Referenced::BelongsTo::Eager

获取此类关联的 Eager对象。

例子:

获取急切加载器对象

参数:

返回:



110
111
112
# File 'lib/mongoid/association/referenced/belongs_to/proxy.rb', line 110

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

嵌入式?false

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

例子:

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

Association::BelongsTo::Proxy.embedded?

返回:

  • ( false )

    始终为 false。



121
122
123
# File 'lib/mongoid/association/referenced/belongs_to/proxy.rb', line 121

def 嵌入式?
  false
end

实例方法详细信息

# nullify对象

通过删除外键和引用来删除基本文档和目标文档之间的关联,并在此进程中孤立目标文档。

例子:

取消关联。

person.game.nullify


39
40
41
42
# File 'lib/mongoid/association/referenced/belongs_to/proxy.rb', line 39

def nullify
  unbind_one
  _target.保存
end

#替换(替换) ⇒ self | nil

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

例子:

替换关联。

name.substitute(new_name)

参数:

返回:

  • ( self | nil )

    关联或 nil。



53
54
55
56
57
58
59
60
# File 'lib/mongoid/association/referenced/belongs_to/proxy.rb', line 53

def 替换(替换)
  unbind_one
  return 除非 替换

  self._target = 规范化(替换)
  bind_one
  self
end