类:Mongoid::Association::Embedded::EmbedsMany

继承:
对象
  • 对象
显示全部
包括:
构建, 可相关
定义于:
lib/mongoid/association/embedded/embeds_many.rb ,
lib/mongoid/association/embedded/embeds_many/proxy.rb,
lib/mongoid/association/embedded/embeds_many/bounding.rb,
lib/mongoid/association/embedded/embeds_many/buildable.rb

Overview

EmbedsMany 类型关联。

在命名空间下定义

模块: 可构建 类: 绑定,代理

常量摘要折叠

ASSOCIATION_OPTIONS =

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

返回:

  • ( Array<Symbol> )

    额外的有效选项。

[
    :as,
    :cascade_callbacks,
    :循环,
    :order,
    :store_as,
    :before_add,
    :after_add,
    :before_remove,
    :after_remove
]
VALID_OPTIONS =

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

返回:

  • ( Array<Symbol> )

    有效选项。

(ASSOCIATION_OPTIONS + SHARED_OPTIONS).冻结

Relatable 中包含的常量

Relatable::PRIMARY_KEY_DEFAULTRelatable::SHARED_OPTIONS

实例属性摘要

Relatable 中包含的属性

#name#options#parent_inclusions

实例方法摘要折叠

Buildable中包含的方法

#build

Relatable 中包含的方法

#==, #bindable?, #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, #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、# touch_field # touchable?

Constrainable中包含的方法

#convert_to_foreign_key

实例方法详细信息

#标准(base, target) ⇒对象

获取用于搜索给定父文档和子文档的条件对象。

参数:

  • 基础 (文档)

    基础文档。

  • 目标 (文档)

    子文档。



137
138
139
140
141
142
143
144
# File 'lib/mongoid/association/embedded/embeds_many.rb', line 137

def 条件(基础, 目标)
  criterion = klass.作用域
  criterion.嵌入式 = true
  criterion.文档 = 目标
  criterion.parent_document = 基础
  criterion.关联 = self
  apply_ordering(criterion)
end

# embedded?true

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

返回:

  • ( true )

    始终为 true。



66
# File 'lib/mongoid/association/embedded/embeds_many.rb', line 66

def 嵌入式? true end

#string

用于获取关联对象属性的键。

返回:

  • ( string )

    用于存储关联的字段的名称。



59
60
61
# File 'lib/mongoid/association/embedded/embeds_many.rb', line 59

def key
  store_as.to_s
end

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

嵌套构建器对象。

参数:

  • 属性 (哈希)

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

  • 选项 (哈希)

    关联的选项。

返回:



116
117
118
# File 'lib/mongoid/association/embedded/embeds_many.rb', line 116

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

#路径(文档) ⇒ Mongoid::Atomic::Paths::Embedded::Many

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

例子:

获取路径计算器。

Proxy.path(document)

参数:

  • 文档 (文档)

    要计算的文档。

返回:



129
130
131
# File 'lib/mongoid/association/embedded/embeds_many.rb', line 129

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

#多态?true | false

此关联是否具有多态性?

返回:

  • ( true | false )

    此关联是否为多态。



97
98
99
# File 'lib/mongoid/association/embedded/embeds_many.rb', line 97

def 多态?
  @poly态 ||= !!@options[:as]
end

#primary_keynil

主键

返回:

  • ( nil )

    与此关联无关



85
# File 'lib/mongoid/association/embedded/embeds_many.rb', line 85

def primary_key end

#关系Association::Embedded::EmbedsMany::Proxy

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

返回:



90
91
92
# File 'lib/mongoid/association/embedded/embeds_many.rb', line 90

def 关系
  代理
end

# setup!self

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

返回:

  • ( self )


42
43
44
45
46
47
# File 'lib/mongoid/association/embedded/embeds_many.rb', line 42

def setup!
  setup_instance_methods!
  @owner_class.embedded_relations = @owner_class.embedded_relations.合并(merge)(名称 => self)
  @owner_class.aliased_fields[名称.to_s] = store_as if store_as
  self
end

#store_asString

用于存储关联对象列表的字段键。

返回:

  • ( string )

    字段名称。



52
53
54
# File 'lib/mongoid/association/embedded/embeds_many.rb', line 52

def store_as
  @store_as ||= (@options[:store_as].try(:to_s) || 名称.to_s)
end

#stores_foreign_key?false

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

返回:

  • ( false )

    始终为 false。



80
# File 'lib/mongoid/association/embedded/embeds_many.rb', line 80

def store_foreign_key? false end

#类型string | nil

注意:

仅当关联是多态时才相关。

用于存储相关对象类型的字段。

返回:

  • ( string | nil )

    用于存储关联对象类型的字段。



106
107
108
# File 'lib/mongoid/association/embedded/embeds_many.rb', line 106

def 类型
  @type ||= " #{ as } _type " if 多态?
end

#validation_defaulttrue

获取关联的默认验证设置。 确定默认情况下是否会发生关联的验证。

例子:

获取验证默认。

Proxy.validation_default

返回:

  • ( true )

    始终为 true。



75
# File 'lib/mongoid/association/embedded/embeds_many.rb', line 75

def validation_default true end