类:Mongoid::Association::Referenced::BelongsTo
- 继承:
-
对象
- 对象
- Mongoid::Association::Referenced::BelongsTo
- 定义于:
- lib/mongoid/association/referenced/belongs_to.rb ,
lib/mongoid/association/referenced/belongs_to/eager.rb,
lib/mongoid/association/referenced/belongs_to/proxy.rb,
lib/mongoid/association/referenced/belongs_to/bounding.rb,
lib/mongoid/association/referenced/belongs_to/buildable.rb
Overview
BelongsTo 类型关联。
在命名空间下定义
模块: 可构建 类: Binding 、 Eager 、 Proxy
常量摘要折叠
- ASSOCIATION_OPTIONS =
除常用选项外,还可用于此类关联的选项。
[ :autobuild, :autosave, :counter_cache, :depend, :foreign_key, :index, :poly态, :primary_key, :touch, :可选, :required, :scope, ].冻结
- VALID_OPTIONS =
此关联的有效选项的完整列表,包括共享选项。
(ASSOCIATION_OPTIONS + SHARED_OPTIONS).冻结
- FOREIGN_KEY_FIELD_TYPE =
保存外键的字段的类型。
对象
- FOREIGN_KEY_SUFFIX =
默认外键后缀。
'_id'.冻结
来自Mongoid::Association::Relatable的常量
Mongoid::Association::Relatable::PRIMARY_KEY_DEFAULT 、 Mongoid::Association::Relatable::SHARED_OPTIONS
实例属性摘要
Mongoid::Association::Relatable 中包含的属性
#name 、 #options 、 #parent_inclusions
实例方法摘要折叠
-
# embedded? ⇒ false
此关联类型是否为嵌入式?
-
# foreign_key ⇒ string
获取用于保存关联引用的外键字段。
-
#inverse_type ⇒ String
用于存储多态关联类型的字段的名称。
-
#nested_builder (attributes, options) ⇒ Association::Nested::One
嵌套构建器对象。
-
#路径(文档)→ 根
获取所提供文档的路径计算器。
-
#多态? ⇒ true | false
此关联是否具有多态性?
-
#关系⇒ Association::BelongsTo::Proxy
获取此关联类型的关联代理类。
-
# relation_complements ⇒ Array<Mongoid::Association::Relatable>
关联补充列表。
-
# 解析器 ⇒ nil | Mongoid::ModelResolver
返回对象将多态类型引用转换为类对象的对象,反之亦然。
-
#作用域⇒ Proc |符号 | nil
获取查询关联时要应用的范围。
-
# 设置! ⇒ self
设置实例方法、字段等。
-
#stores_foreign_key? ⇒ true
此关联类型是否存储外键?
-
#validation_default ⇒ false
用于验证关联对象的默认。
Buildable中包含的方法
Mongoid::Association::Relatable 中包含的方法
#== , #bindable? 、 #counter_cache_column_name 、 #create_relation 、 #什么呢? 、 #extension 、 #foreign_key_check 、 #foreign_key_setter 、 #get_callbacks 、 #in_to? 、 #initialize 、 #inverse 、 #inverse_association 、 #inverse_class 、 #inverse_class_name 、 #inverse_setter 、 #inverse_type_setter 、 #inverses 、 #key 、 #many? , #one? 、# relation_class 、# relation_class_name 、#setter、# type_setter 、 # validate?
选项中包含的方法
#as , #autoBuilding? 、 #autosave 、 #cascading_callbacks? , #counter_cached? , #cycle? 、#depend、# forced_nil_inverse ? , #indexed? 、#inverse_of、# order 、#primary_key、# store_as 、 # touch_field 、 # touchable? , #type
Constrainable中包含的方法
实例方法详细信息
# embedded? ⇒ false
此关联类型是否为嵌入式?
77 |
# File 'lib/mongoid/association/referenced/belongs_to.rb', line 77 def ; false; end |
# foreign_key ⇒ string
获取用于保存关联引用的外键字段。
87 88 89 90 |
# File 'lib/mongoid/association/referenced/belongs_to.rb', line 87 def foreign_key @foreign_key ||= @options[:foreign_key] ? @options[:foreign_key].to_s : default_foreign_key_field end |
#inverse_type ⇒ String
用于存储多态关联类型的字段的名称。
124 125 126 |
# File 'lib/mongoid/association/referenced/belongs_to.rb', line 124 def inverse_type (@inverse_type ||= "#{name}_type") if 多态? end |
#nested_builder (attributes, options) ⇒ Association::Nested::One
嵌套构建器对象。
134 135 136 |
# File 'lib/mongoid/association/referenced/belongs_to.rb', line 134 def nested_builder(属性, ) 嵌套::one.new(self, 属性, ) end |
#路径(文档)→根
获取所提供文档的路径计算器。
146 147 148 |
# File 'lib/mongoid/association/referenced/belongs_to.rb', line 146 def 路径(文档) Mongoid::原子性::路径::根.new(文档) end |
#多态? ⇒ true | false
此关联是否具有多态性?
102 103 104 |
# File 'lib/mongoid/association/referenced/belongs_to.rb', line 102 def 多态? @poly态 ||= !!@options[:poly态] end |
#关系⇒ Association::BelongsTo::Proxy
获取此关联类型的关联代理类。
95 96 97 |
# File 'lib/mongoid/association/referenced/belongs_to.rb', line 95 def 关系 代理 end |
# relation_complements ⇒ Array< Mongoid::Association::Relatable >
关联补充列表。
56 57 58 |
# File 'lib/mongoid/association/referenced/belongs_to.rb', line 56 def lation_complements @relation_complements ||= [ 有很多, 有一个 ].冻结 end |
# 解析器 ⇒ nil | Mongoid::ModelResolver
返回对象将多态类型引用转换为类对象的对象,反之亦然。 这是通过定义关联时提供的 ':polyphic' 选项获得的。
请参阅 Mongoid::ModelResolver.resolver 了解此处如何解释 ':poly态ic` 选项。
117 118 119 |
# File 'lib/mongoid/association/referenced/belongs_to.rb', line 117 def 解析器 @resolver ||= Mongoid::ModelResolver.解析器(@options[:poly态]) end |
#scope ⇒ Proc | Symbol | nil
获取查询关联时要应用的范围。
153 154 155 |
# File 'lib/mongoid/association/referenced/belongs_to.rb', line 153 def 范围 @options[:scope] end |
# setup! ⇒ self
在关联所属类上设置实例方法、字段等。
63 64 65 66 67 |
# File 'lib/mongoid/association/referenced/belongs_to.rb', line 63 def setup! setup_instance_methods! @owner_class.aliased_fields[名称.to_s] = foreign_key self end |
#stores_foreign_key? ⇒ true
此关联类型是否存储外键?
72 |
# File 'lib/mongoid/association/referenced/belongs_to.rb', line 72 def store_foreign_key?; true; end |
# validation_default ⇒ false
用于验证关联对象的默认。
82 |
# File 'lib/mongoid/association/referenced/belongs_to.rb', line 82 def validation_default; false; end |