模块:Mongoid::Association::Referenced::HasOne::Buildable
- 定义于:
- lib/mongoid/association/referenced/has_one/buildable.rb
Overview
has_one 关联的 Builder 行为。
实例方法摘要折叠
-
# build (base, object, _type = nil, Selected_fields = nil) ⇒ 文档
此方法要么采用_id或对象,并使用该ID查询反向,要么在清除关联对象后设置该对象。
WithPolymorphicCriteria 中包含的方法
实例方法详细信息
# 构建 (base, 对象, _type = nil, Selected_fields = nil) ⇒文档
此方法要么采用_id或对象,并使用该ID查询反向,要么在清除关联对象后设置该对象。
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mongoid/association/referenced/has_one/buildable.rb', line 23 def 构建(基础, 对象, _type = nil, created_fields = nil) if 查询?(对象) # 处理 $lookup聚合中的数组哈希 if 对象.is_a?(阵列) && 对象.全部? { |o| o.is_a?(哈希) } doc = 对象.first return doc ? 工厂.execute_from_db(klass, doc, nil, created_fields, execute_callbacks: false) : nil end execute_query(对象, 基础) 除非 基础.new_record? else clear_关联(对象) 对象 end end |