类:Mongoid::Association::Referenced::BelongsTo::Binding
- 继承:
-
对象
- 对象
- Mongoid::Association::Referenced::BelongsTo::Binding
- 包括:
- Bindable
- 定义于:
- lib/mongoid/association/referenced/belongs_to/bounding.rb
Overview
belongs_to 关联的绑定类。
实例属性摘要
Bindable中包含的属性
#_association 、 #_base 、 #_target
实例方法摘要折叠
-
# bind_one ⇒ 对象
将基础对象绑定到关联的反向对象。
-
# unbind_one ⇒ 对象
通过将引用设置为 nil 来解除基础对象和反向对象的绑定。
Bindable中包含的方法
实例方法详细信息
# bind_one ⇒对象
将基础对象绑定到关联的反向对象。 这样我们就可以在两侧引用实际对象本身。
这种情况会在反向对象和文档本身上设置关联。
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/mongoid/association/referenced/belongs_to/bounding.rb', line 22 def bind_one 绑定 do check_poly态_inverses!(_target) bind_foreign_key(_base, record_id(_target)) #设立反向类型(例如 "#{name}_type") 用于新的多态关联 if _association.inverse_type && !_base.冻结? key = _association.解析器.default_key_for(_target) bind_poly态_inverse_type(_base, key) end if 反向 = _association.反向(_target) if set_base_association if _base.referenced_many? _target.__send__(反向).推动(_base) else remove_关联(_target) _target.set_relation(反向, _base) end end end end end |
# unbind_one ⇒对象
通过将引用设置为 nil 来解除基础对象和反向对象的绑定。
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/mongoid/association/referenced/belongs_to/bounding.rb', line 52 def unbind_one 绑定 do 反向 = _association.反向(_target) bind_foreign_key(_base, nil) bind_poly态_inverse_type(_base, nil) if 反向 set_base_association if _base.referenced_many? _target.__send__(反向).删除(_base) else _target.set_relation(反向, nil) end end end end |