类:Mongoid::Association::Referenced::HasAndBelongsToMany

继承:
对象
  • 对象
显示全部
包括:
Buildable , Mongoid::Association::Relatable
定义于:
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 类型关联。

在命名空间下定义

模块: 可构建 类: BindingEagerProxy

常量摘要折叠

ASSOCIATION_OPTIONS =

除常用选项外,还可用于此类关联的选项。

返回:

  • ( Array<Symbol> )

    额外的有效选项。

%i[
  after_add
  after_remove
  autosave
  before_add
  before_remove
  counter_cache
  依赖
  foreign_key
  索引(index)
  来自一个购物车应用的order文档,
  primary_key
  inverse_primary_key
  inverse_foreign_key
  范围
].冻结
VALID_OPTIONS =

此关联的有效选项的完整列表,包括共享选项。

返回:

  • ( Array<Symbol> )

    有效选项。

(ASSOCIATION_OPTIONS + SHARED_OPTIONS).冻结
FOREIGN_KEY_FIELD_TYPE =

保存外键的字段的类型。

返回:

  • 数组
阵列
FOREIGN_KEY_SUFFIX =

默认外键后缀。

返回:

  • ( string )

    ' _ids '

'_ids'

来自Mongoid::Association::Relatable的常量

Mongoid::Association::Relatable::PRIMARY_KEY_DEFAULTMongoid::Association::Relatable::SHARED_OPTIONS

实例属性摘要

Mongoid::Association::Relatable 中包含的属性

#name#options#owner_class#parent_inclusions

实例方法摘要折叠

Buildable中包含的方法

#build

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中包含的方法

#convert_to_foreign_key

实例方法详细信息

#可绑定? (doc) ⇒ true | false

尝试使用此关联绑定对象是否会引发错误。

参数:

  • doc (文档)

    要绑定的文档。

返回:

  • ( true | false )

    是否可以绑定文档。



143
144
145
# File 'lib/mongoid/association/referenced/has_and_belongs_to_many.rb', line 143

def 可绑定?(doc)
  forced_nil_inverse? || (!!反向 && doc.字段.密钥.包括?(foreign_key))
end

# Criteria (base, id_list = nil) ⇒ Mongoid::Criteria

用于查询此关联的条件。

返回:



117
118
119
# File 'lib/mongoid/association/referenced/has_and_belongs_to_many.rb', line 117

def 条件(基础, id_list = nil)
  query_criteria(id_list || 基础.发送(foreign_key))
end

# embedded?false

此关联类型是否为嵌入式?

返回:

  • ( false )

    始终为 false。



71
72
73
# File 'lib/mongoid/association/referenced/has_and_belongs_to_many.rb', line 71

def 嵌入式?
  false
end

#forced_nil_inverse?true | false

ID 是否只保存在关联的这一端?

返回:

  • ( true | false )

    此关联是否具有强制反向 nil。



85
86
87
# File 'lib/mongoid/association/referenced/has_and_belongs_to_many.rb', line 85

def forced_nil_inverse?
  @forced_nil_inverse ||= @options.键?(:inverse_of) && !@options[:inverse_of]
end

# foreign_keystring

获取用于保存关联引用的外键字段。

返回:

  • ( string )

    用于保存关联引用的外键字段。



106
107
108
109
110
111
112
# File 'lib/mongoid/association/referenced/has_and_belongs_to_many.rb', line 106

def foreign_key
  @foreign_key ||= if @options[:foreign_key]
                     @options[:foreign_key].to_s
                   else
                     default_foreign_key_field
                   end
end

# inverse_foreign_keystring

获取反向的外键字段。

返回:

  • ( string )

    用于在反向保存关联引用的外键字段。



125
126
127
128
129
130
131
132
133
134
135
# File 'lib/mongoid/association/referenced/has_and_belongs_to_many.rb', line 125

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_setterString

获取相反的外键设置器。

返回:

  • ( string )

    用于在反向保存关联引用的外键设置器。



151
152
153
# File 'lib/mongoid/association/referenced/has_and_belongs_to_many.rb', line 151

def inverse_foreign_key_setter
  @inverse_foreign_key_setter ||= " #{ inverse_foreign_key } = " if inverse_foreign_key
end

#nested_builder (attributes, options) ⇒ Association::Nested::One

嵌套构建器对象。

参数:

  • 属性 (哈希)

    用于构建关联对象的属性。

  • 选项 (哈希)

    关联的选项。

返回:



161
162
163
# File 'lib/mongoid/association/referenced/has_and_belongs_to_many.rb', line 161

def nested_builder(属性, 选项)
  嵌套::很多.new(self, 属性, 选项)
end

#路径(文档)→

获取所提供文档的路径计算器。

例子:

获取路径计算器。

association.path(document)

参数:

  • 文档 (文档)

    要计算的文档。

返回:

  • ( Root )

    根原子路径计算器。



173
174
175
# File 'lib/mongoid/association/referenced/has_and_belongs_to_many.rb', line 173

def 路径(文档)
  Mongoid::原子性::路径::.new(文档)
end

#关系Association::HasAndBelongsToMany::Proxy

获取此关联类型的关联代理类。

返回:

  • ( Association::HasAndBelongsToMany::Proxy )

    代理类。



99
100
101
# File 'lib/mongoid/association/referenced/has_and_belongs_to_many.rb', line 99

def 关系
  代理
end

# relation_complementsArray< Mongoid::Association::Relatable >

关联补充列表。

返回:



56
57
58
# File 'lib/mongoid/association/referenced/has_and_belongs_to_many.rb', line 56

def lation_complements
  @relation_complements ||= [ self.class ].冻结
end

#scopeProc | Symbol | nil

获取查询关联时要应用的范围。

返回:

  • (Proc | Symbol | nil)

    关联范围(如果有)。



180
181
182
# File 'lib/mongoid/association/referenced/has_and_belongs_to_many.rb', line 180

def 范围
  @options[:scope]
end

# setup!self

在关联所属类上设置实例方法、字段等。

返回:

  • ( self )


63
64
65
66
# File 'lib/mongoid/association/referenced/has_and_belongs_to_many.rb', line 63

def setup!
  setup_instance_methods!
  self
end

#stores_foreign_key?true

此关联类型是否存储外键?

返回:

  • ( true )

    始终为 true。



92
93
94
# File 'lib/mongoid/association/referenced/has_and_belongs_to_many.rb', line 92

def store_foreign_key?
  true
end

# validation_defaultfalse

用于验证关联对象的默认。

返回:

  • ( false )

    始终为 false。



78
79
80
# File 'lib/mongoid/association/referenced/has_and_belongs_to_many.rb', line 78

def validation_default
  true
end