类:Mongoid::Association::Referenced::HasAndBelongsToMany
- 继承:
-
对象
- 对象
- Mongoid::Association::Referenced::HasAndBelongsToMany
- 定义于:
- lib/mongoid/association/referenced/has_and_belongs_to_many.rb ,
lib/mongoid/association/referenced/has_and_belongs_to_many/eager.rb,
lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb,
lib/mongoid/association/referenced/has_and_belongs_to_many/bounding.rb,
lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb
Overview
HasAndBelongsToMany 类型关联。
在命名空间下定义
模块: 可构建 类: Binding 、 Eager 、 Proxy
常量摘要折叠
- ASSOCIATION_OPTIONS =
除常用选项外,还可用于此类关联的选项。
[ :after_add, :after_remove, :autosave, :before_add, :before_remove, :counter_cache, :depend, :foreign_key, :index, :order, :primary_key, :inverse_primary_key, :inverse_foreign_key, :scope, ].冻结
- VALID_OPTIONS =
此关联的有效选项的完整列表,包括共享选项。
(ASSOCIATION_OPTIONS + SHARED_OPTIONS).冻结
- FOREIGN_KEY_FIELD_TYPE =
保存外键的字段的类型。
阵列
- FOREIGN_KEY_SUFFIX =
默认外键后缀。
' _ids '.冻结
来自Mongoid::Association::Relatable的常量
Mongoid::Association::Relatable::PRIMARY_KEY_DEFAULT 、 Mongoid::Association::Relatable::SHARED_OPTIONS
实例属性摘要
Mongoid::Association::Relatable 中包含的属性
#name 、 #options 、 #parent_inclusions
实例方法摘要折叠
-
#可绑定? (doc) ⇒ true | false
尝试使用此关联绑定对象是否会引发错误。
-
# Criteria (base, id_list = nil) ⇒ Mongoid::Criteria
用于查询此关联的条件。
-
# embedded? ⇒ false
此关联类型是否为嵌入式?
-
#forced_nil_inverse? ⇒ true | false
id 是否只保存在关联的这一端?
-
# foreign_key ⇒ string
获取用于保存关联引用的外键字段。
-
# inverse_foreign_key ⇒ string
获取反向的外键字段。
-
#inverse_foreign_key_setter ⇒ String
获取相反的外键设置器。
-
#nested_builder (attributes, options) ⇒ Association::Nested::One
嵌套构建器对象。
-
#路径(文档)→ 根
获取所提供文档的路径计算器。
-
#关系⇒ Association::HasAndBelongsToMany::Proxy
获取此关联类型的关联代理类。
-
# relation_complements ⇒ Array<Mongoid::Association::Relatable>
关联补充列表。
-
#作用域⇒ Proc |符号 | nil
获取查询关联时要应用的范围。
-
# 设置! ⇒ self
设置实例方法、字段等。
-
#stores_foreign_key? ⇒ true
此关联类型是否存储外键?
-
#validation_default ⇒ false
用于验证关联对象的默认。
Buildable中包含的方法
Mongoid::Association::Relatable 中包含的方法
#==, #counter_cache_column_name, #create_relation, #destructive?, #extension, #foreign_key_check, #foreign_key_setter, #get_callbacks, #in_to?, #initialize, #inverse, #inverse_association, #inverse_class, #inverse_class_name, #inverse_setter, #inverse_type, #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 、 #indexed? 、 #inverse_of 、 #order 、 #poly态? 、 #primary_key 、 #store_as 、 #touch_field 、 #touchable? , #type
Constrainable中包含的方法
实例方法详细信息
#可绑定? (doc) ⇒ true | false
尝试使用此关联绑定对象是否会引发错误。
136 137 138 |
# File 'lib/mongoid/association/referenced/has_and_belongs_to_many.rb', line 136 def 可绑定?(doc) forced_nil_inverse? || (!!反向 && doc.字段.密钥.包括?(foreign_key)) end |
# Criteria (base, id_list = nil) ⇒ Mongoid::Criteria
用于查询此关联的条件。
110 111 112 |
# File 'lib/mongoid/association/referenced/has_and_belongs_to_many.rb', line 110 def 条件(基础, id_list = nil) query_criteria(id_list || 基础.发送(foreign_key)) end |
# embedded? ⇒ false
此关联类型是否为嵌入式?
73 |
# File 'lib/mongoid/association/referenced/has_and_belongs_to_many.rb', line 73 def ; false; end |
#forced_nil_inverse? ⇒ true | false
ID 是否只保存在关联的这一端?
83 84 85 |
# File 'lib/mongoid/association/referenced/has_and_belongs_to_many.rb', line 83 def forced_nil_inverse? @forced_nil_inverse ||= @options.键?(:inverse_of) && !@options[:inverse_of] end |
# foreign_key ⇒ string
获取用于保存关联引用的外键字段。
102 103 104 105 |
# File 'lib/mongoid/association/referenced/has_and_belongs_to_many.rb', line 102 def foreign_key @foreign_key ||= @options[:foreign_key] ? @options[:foreign_key].to_s : default_foreign_key_field end |
# inverse_foreign_key ⇒ string
获取反向的外键字段。
118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/mongoid/association/referenced/has_and_belongs_to_many.rb', line 118 def inverse_foreign_key if @options.键?(:inverse_foreign_key) @options[:inverse_foreign_key] elsif @options.键?(:inverse_of) inverse_of ? " #{ inverse_of . to_s . Singleize } #{ FOREIGN_KEY_SUFFIX } " : nil elsif inv = inverse_association&。foreign_key inv else " #{ inverse_class_name . demodulize . underscore } #{ FOREIGN_KEY_SUFFIX } " end end |
#inverse_foreign_key_setter ⇒ String
获取相反的外键设置器。
144 145 146 |
# File 'lib/mongoid/association/referenced/has_and_belongs_to_many.rb', line 144 def inverse_foreign_key_setter @inverse_foreign_key_setter ||= " #{ inverse_foreign_key } = " if inverse_foreign_key end |
#nested_builder (attributes, options) ⇒ Association::Nested::One
嵌套构建器对象。
154 155 156 |
# File 'lib/mongoid/association/referenced/has_and_belongs_to_many.rb', line 154 def nested_builder(属性, ) 嵌套::很多.new(self, 属性, ) end |
#路径(文档)→根
获取所提供文档的路径计算器。
166 167 168 |
# File 'lib/mongoid/association/referenced/has_and_belongs_to_many.rb', line 166 def 路径(文档) Mongoid::原子性::路径::根.new(文档) end |
#关系⇒ Association::HasAndBelongsToMany::Proxy
获取此关联类型的关联代理类。
95 96 97 |
# File 'lib/mongoid/association/referenced/has_and_belongs_to_many.rb', line 95 def 关系 代理 end |
# relation_complements ⇒ Array< Mongoid::Association::Relatable >
关联补充列表。
58 59 60 |
# File 'lib/mongoid/association/referenced/has_and_belongs_to_many.rb', line 58 def lation_complements @relation_complements ||= [ self.class ].冻结 end |
#scope ⇒ Proc | Symbol | nil
获取查询关联时要应用的范围。
173 174 175 |
# File 'lib/mongoid/association/referenced/has_and_belongs_to_many.rb', line 173 def 范围 @options[:scope] end |
# setup! ⇒ self
在关联所属类上设置实例方法、字段等。
65 66 67 68 |
# File 'lib/mongoid/association/referenced/has_and_belongs_to_many.rb', line 65 def setup! setup_instance_methods! self end |
#stores_foreign_key? ⇒ true
此关联类型是否存储外键?
90 |
# File 'lib/mongoid/association/referenced/has_and_belongs_to_many.rb', line 90 def store_foreign_key?; true; end |
# validation_default ⇒ false
用于验证关联对象的默认。
78 |
# File 'lib/mongoid/association/referenced/has_and_belongs_to_many.rb', line 78 def validation_default; true; end |