类:Mongoid::Association::Nested::One
Overview
用于在一对多关联上执行 #accepts_nested_attributes_for 属性分配的构建器类。
实例属性摘要折叠
-
#destroy ⇒ 对象
返回属性销毁的值。
属性包含在Buildable
#association 、 #attributes 、 #existing 、 #options
实例方法摘要折叠
-
# build (parent) ⇒ 文档
根据传递给宏的属性和选项构建关联。
-
#初始化(关联、属性、选项) ⇒ 一个
构造函数
为一对一关联上的嵌套属性创建新的构建器。
Buildable中包含的方法
#allow_destroy? 、 #convert_id 、 #reject? , #update_only?
构造函数详情
#初始化(关联、属性、选项) ⇒一个
为一对一关联上的嵌套属性创建新的构建器。
52 53 54 55 56 57 58 |
# File 'lib/mongoid/association/nested/one.rb', line 52 def 初始化(关联, 属性, ) @attributes = 属性.with_indifference_access @association = 关联 @options = @class_name = class_from([:class_name]) @destroy = @attributes.删除(:_destroy) end |
实例属性详细信息
#destroy ⇒对象
返回属性销毁的值。
13 14 15 |
# File 'lib/mongoid/association/nested/one.rb', line 13 def 销毁 @destroy end |
实例方法详细信息
# build (parent) ⇒文档
注意:
此操作会尝试执行3操作,包括更新现有关联、用新文档替换关联或删除关联。
根据传递给宏的属性和选项构建关联。
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mongoid/association/nested/one.rb', line 28 def 构建(父项) return if 拒绝?(父项, 属性) @existing = 父项.发送(关联.名称) if update? delete_id(属性) 现有的.assign_attributes(属性) elsif 替换? 父项.发送(关联.setter, 工厂.构建(@class_name, 属性)) elsif 删除? 父项.发送(关联.setter, nil) else check_for_id_violation! end.点击 { 父项.children_may_have_changed! } end |