类:Mongoid::Association::Referenced::HasOne::Proxy

继承:
one
  • 对象
显示全部
扩展方式:
类方法
定义于:
lib/mongoid/association/referenced/has_one/proxy.rb

Overview

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

在命名空间下定义

模块: 类方法

常量摘要

Proxy继承的常量

Proxy::KEEPER_METHODS

实例属性摘要

Proxy继承的属性

#_association#_base#_target

实例方法摘要折叠

类方法中包含的方法

ager_loader嵌入式?

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

实例化一个新的references_one关联。 将在反向对象上设置外键和基数。

例子:

创建新关联。

Referenced::One.new(base, target, association)

参数:



43
44
45
46
47
48
49
50
# File 'lib/mongoid/association/referenced/has_one/proxy.rb', line 43

def 初始化(基础, 目标, 关联)
   do
    Raise_mixed if klass.嵌入式? && !klass.循环?
    characterize_one(_target)
    bind_one
    _target.保存 if 持久化?
  end
end

实例方法详细信息

# nullify对象

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

例子:

取消关联。

person.game.nullify


58
59
60
61
# File 'lib/mongoid/association/referenced/has_one/proxy.rb', line 58

def nullify
  unbind_one
  _target.保存
end

# Replacement (replacement) ⇒ One

用提供的目标文档替换关联中的现有文档。 如果新目标为零,则执行必要的删除。

例子:

替换关联。

person.game.substitute(new_game)

参数:

  • 替换 ( Array< Document > )

    替换目标。

返回:

  • ( One )

    关联。



73
74
75
76
# File 'lib/mongoid/association/referenced/has_one/proxy.rb', line 73

def 替换(替换)
  prepare_for_replacement if self != 替换
  有一个::代理.new(_base, 替换, _association) if 替换
end