类:Mongoid::Association::Embedded::EmbedsOne::Binding

继承:
对象
  • 对象
显示全部
包括:
Bindable
定义于:
lib/mongoid/association/embedded/embeds_one/bounding.rb

Overview

所有 embeds_one 关联的绑定类。

实例属性摘要

Bindable中包含的属性

#_association#_base#_target

实例方法摘要折叠

Bindable中包含的方法

#bounding#initialize

实例方法详细信息

# bind_one对象

将基础对象绑定到关联的反向对象。 这样我们就可以在两侧引用实际对象本身。

这种情况会在反向对象以及文档本身上设置关联元数据。

例子:

绑定文档。

person.name.bind(:continue => true)
person.name = Name.new


22
23
24
25
26
27
# File 'lib/mongoid/association/embedded/embeds_one/ Binding.rb', line 22

def bind_one
  _target.(_base)
  绑定 do
    try_method(_target, _association.inverse_setter(_target), _base)
  end
end

# unbind_one对象

通过将引用设置为 nil 来解除基础对象和反向对象的绑定。

例子:

解除文档绑定。

person.name.unbind(:continue => true)
person.name = nil


35
36
37
38
39
# File 'lib/mongoid/association/embedded/embeds_one/ Binding.rb', line 35

def unbind_one
  绑定 do
    try_method(_target, _association.inverse_setter(_target), nil)
  end
end