模块:Mongoid::Association::Accessors
Overview
此模块包含与通过 getter 和 setter 访问关联相关的所有行为,以及如何委托构建者以创建新关联。
实例方法摘要折叠
-
# __build__ (name, 对象,association,selected_fields = nil) ⇒ 代理
构建相关文档并创建关联,除非该文档为零,然后对此文档设置关联。
-
# create_relation (对象,association,selected_fields = nil) ⇒ 代理
从对象和关联元数据创建关联。
-
# reset_relation_criteria (name) ⇒ 对象
重置关联代理内的条件。
-
# set_relation (name, relation) ⇒ 代理
将提供的关联设置为具有提供名称的类上的实例变量。
实例方法详细信息
# __build__ (name, 对象,association,selected_fields = nil) ⇒代理
构建相关文档并创建关联,除非该文档为零,然后对此文档设置关联。
27 28 29 30 |
# File 'lib/mongoid/association/accessors.rb', line 27 def __build__(名称, 对象, 关联, created_fields = nil) 关系 = create_relation(对象, 关联, created_fields) set_relation(名称, 关系) end |
# create_relation (对象,association,selected_fields = nil) ⇒代理
从对象和关联元数据创建关联。
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/mongoid/association/accessors.rb', line 44 def create_relation(对象, 关联, created_fields = nil) key = @attributes[关联.inverse_type] 类型 = key ? 关联.解析器.model_for(key) : nil 目标 = if t = 关联.构建(self, 对象, 类型, created_fields) 关联.create_relation(self, t) else nil end # 只需要对嵌入式关联执行此操作。 待处理的回调 # 仅在物化文档时添加,这种情况只发生 # 针对嵌入式关联。 中没有调用数据库 # 构建引用关联。 if 关联. 阵列(目标).每 do |doc| doc.try(:run_pending_callbacks) end end 目标 end |
# reset_relation_criteria (name) ⇒对象
重置关联代理内的条件。 由多对多关联用于使根本的id大量保持同步。
73 74 75 76 77 |
# File 'lib/mongoid/association/accessors.rb', line 73 def reset_relation_criteria(名称) if instance_variable_defined?(" @_ #{ name } ") 发送(名称).reset_unloaded end end |
# set_relation (name, relation) ⇒代理
将提供的关联设置为具有提供名称的类上的实例变量。 用作助手,只是为了保持代码简洁。
89 90 91 |
# File 'lib/mongoid/association/accessors.rb', line 89 def set_relation(名称, 关系) instance_variable_set(" @_ #{ name } ", 关系) end |