类:Mongoid::Association::Embedded::EmbedsOne

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

Overview

EmbedsOne 类型关联。

在命名空间下定义

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

常量摘要折叠

ASSOCIATION_OPTIONS =

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

返回:

  • ( Array<Symbol> )

    额外的有效选项。

[
    :autobuild,
    :as,
    :cascade_callbacks,
    :循环,
    :store_as
]
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?, #path, #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

实例方法详细信息

# embedded?true

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

返回:

  • ( true )

    始终为 true。



62
# File 'lib/mongoid/association/embedded/embeds_one.rb', line 62

def 嵌入式? true end

#string

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

返回:

  • ( string )

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



55
56
57
# File 'lib/mongoid/association/embedded/embeds_one.rb', line 55

def key
  store_as.to_s
end

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

嵌套构建器对象。

参数:

  • 属性 (哈希)

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

  • 选项 (哈希)

    关联的选项。

返回:



112
113
114
# File 'lib/mongoid/association/embedded/embeds_one.rb', line 112

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

#多态?true | false

此关联是否具有多态性?

返回:

  • ( true | false )

    此关联是否为多态。



93
94
95
# File 'lib/mongoid/association/embedded/embeds_one.rb', line 93

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

#primary_keynil

主键

返回:

  • ( nil )

    与此关联无关



81
# File 'lib/mongoid/association/embedded/embeds_one.rb', line 81

def primary_key end

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

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

返回:



86
87
88
# File 'lib/mongoid/association/embedded/embeds_one.rb', line 86

def 关系
  代理
end

# setup!self

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

返回:

  • ( self )


38
39
40
41
42
43
# File 'lib/mongoid/association/embedded/embeds_one.rb', line 38

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 )

    字段名称。



48
49
50
# File 'lib/mongoid/association/embedded/embeds_one.rb', line 48

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

#stores_foreign_key?false

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

返回:

  • ( false )

    始终为 false。



76
# File 'lib/mongoid/association/embedded/embeds_one.rb', line 76

def store_foreign_key? false end

#类型string | nil

注意:

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

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

返回:

  • ( string | nil )

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



102
103
104
# File 'lib/mongoid/association/embedded/embeds_one.rb', line 102

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

# validation_defaulttrue | false

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

例子:

获取验证默认。

Proxy.validation_default

返回:

  • ( true | false )

    验证默认值。



71
# File 'lib/mongoid/association/embedded/embeds_one.rb', line 71

def validation_default true end