类:Mongoid::Association::Referenced::HasOne

继承:
对象
  • 对象
显示全部
包括:
Buildable , Mongoid::Association::Relatable
定义于:
lib/mongoid/association/referenced/has_one.rb ,
lib/mongoid/association/referenced/has_one/eager.rb,
lib/mongoid/association/referenced/has_one/proxy.rb,
lib/mongoid/association/referenced/has_one/bounding.rb,
lib/mongoid/association/referenced/has_one/buildable.rb

Overview

has_one 关联。

在命名空间下定义

模块: 可构建 类: BindingEagerProxy

常量摘要折叠

ASSOCIATION_OPTIONS =

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

返回:

  • ( Array<Symbol> )

    额外的有效选项。

[
    :as,
    :autobuild,
    :autosave,
    :depend,
    :foreign_key,
    :primary_key,
    :scope,
].冻结
VALID_OPTIONS =

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

返回:

  • ( Array<Symbol> )

    有效选项。

(ASSOCIATION_OPTIONS + SHARED_OPTIONS).冻结
FOREIGN_KEY_SUFFIX =

默认外键后缀。

返回:

  • ( string )

    '_id'

'_id'.冻结

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

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

实例属性摘要

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

#name#options#parent_inclusions

实例方法摘要折叠

Buildable中包含的方法

#build

WithPolymorphicCriteria 中包含的方法

#with_poly态_criterion

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、# forced_nil_inverse ? , #indexed? 、#inverse_of、# order 、#primary_key、# store_as # touch_field # touchable?

Constrainable中包含的方法

#convert_to_foreign_key

实例方法详细信息

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

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

参数:

  • doc (文档)

    要绑定的文档。

返回:

  • ( true | false )

    是否可以绑定文档。



116
117
118
# File 'lib/mongoid/association/referenced/has_one.rb', line 116

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

# embedded?false

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

返回:

  • ( false )

    始终为 false。



70
# File 'lib/mongoid/association/referenced/has_one.rb', line 70

def 嵌入式? false end

# foreign_keystring

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

返回:

  • ( string )

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



62
63
64
65
# File 'lib/mongoid/association/referenced/has_one.rb', line 62

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

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

嵌套构建器对象。

参数:

  • 属性 (哈希)

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

  • 选项 (哈希)

    关联的选项。

返回:



90
91
92
# File 'lib/mongoid/association/referenced/has_one.rb', line 90

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

#路径(文档)→

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

例子:

获取路径计算器。

Proxy.path(document)

参数:

  • 文档 (文档)

    要计算的文档。

返回:

  • ( Root )

    根原子路径计算器。



133
134
135
# File 'lib/mongoid/association/referenced/has_one.rb', line 133

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

#多态?true | false

此关联是否具有多态性?

返回:

  • ( true | false )

    此关联是否为多态。



97
98
99
# File 'lib/mongoid/association/referenced/has_one.rb', line 97

def 多态?
  @poly态 ||= !!作为
end

#关系Association::HasOne::Proxy

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

返回:

  • ( Association::HasOne::Proxy )

    代理类。



80
81
82
# File 'lib/mongoid/association/referenced/has_one.rb', line 80

def 关系
  代理
end

# relation_complementsArray< Mongoid::Association::Relatable >

关联补充列表。

返回:



46
47
48
# File 'lib/mongoid/association/referenced/has_one.rb', line 46

def lation_complements
  @relation_complements ||= [ 引用::属于关联 ].冻结
end

#scopeProc | Symbol | nil

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

返回:

  • (Proc | Symbol | nil)

    关联范围(如果有)。



140
141
142
# File 'lib/mongoid/association/referenced/has_one.rb', line 140

def 范围
  @options[:scope]
end

# setup!self

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

返回:

  • ( self )


53
54
55
56
# File 'lib/mongoid/association/referenced/has_one.rb', line 53

def setup!
  setup_instance_methods!
  self
end

#stores_foreign_key?false

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

返回:

  • ( false )

    始终为 false。



123
# File 'lib/mongoid/association/referenced/has_one.rb', line 123

def store_foreign_key? false end

#类型string | nil

注意:

仅与多态关联相关。

如果该关联是多态的,则为该关联的类型。

返回:

  • ( string | nil )

    类型字段。



106
107
108
# File 'lib/mongoid/association/referenced/has_one.rb', line 106

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

#validation_defaulttrue

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

返回:

  • ( true )

    始终为 true。



75
# File 'lib/mongoid/association/referenced/has_one.rb', line 75

def validation_default true end