类:Mongoid::Association::Referenced::BelongsTo

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

Overview

BelongsTo 类型关联。

在命名空间下定义

模块: 可构建 类: BindingEagerProxy

常量摘要折叠

ASSOCIATION_OPTIONS =

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

返回:

  • ( Array<Symbol> )

    额外的有效选项。

[
    :autobuild,
    :autosave,
    :counter_cache,
    :depend,
    :foreign_key,
    :index,
    :poly态,
    :primary_key,
    :touch,
    :可选,
    :required,
    :scope,
].冻结
VALID_OPTIONS =

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

返回:

  • ( Array<Symbol> )

    有效选项。

(ASSOCIATION_OPTIONS + SHARED_OPTIONS).冻结
FOREIGN_KEY_FIELD_TYPE =

保存外键的字段的类型。

返回:

  • 对象
对象
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

Mongoid::Association::Relatable 中包含的方法

#== , #bindable?#counter_cache_column_name#create_relation#什么呢?#extension#foreign_key_check#foreign_key_setter#get_callbacks#in_to?#initialize#inverse#inverse_association#inverse_class#inverse_class_name#inverse_setter#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? , #type

Constrainable中包含的方法

#convert_to_foreign_key

实例方法详细信息

# embedded?false

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

返回:

  • ( false )

    始终为 false。



77
# File 'lib/mongoid/association/referenced/belongs_to.rb', line 77

def 嵌入式? false end

# foreign_keystring

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

返回:

  • ( string )

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



87
88
89
90
# File 'lib/mongoid/association/referenced/belongs_to.rb', line 87

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

#inverse_typeString

用于存储多态关联类型的字段的名称。

返回:

  • ( string )

    该字段用于存储多态关联的类型。



124
125
126
# File 'lib/mongoid/association/referenced/belongs_to.rb', line 124

def inverse_type
  (@inverse_type ||= "#{name}_type") if 多态?
end

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

嵌套构建器对象。

参数:

  • 属性 (哈希)

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

  • 选项 (哈希)

    关联的选项。

返回:



134
135
136
# File 'lib/mongoid/association/referenced/belongs_to.rb', line 134

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

#路径(文档)→

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

例子:

获取路径计算器。

association.path(document)

参数:

  • 文档 (文档)

    要计算的文档。

返回:

  • ( Root )

    根原子路径计算器。



146
147
148
# File 'lib/mongoid/association/referenced/belongs_to.rb', line 146

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

#多态?true | false

此关联是否具有多态性?

返回:

  • ( true | false )

    此关联是否为多态。



102
103
104
# File 'lib/mongoid/association/referenced/belongs_to.rb', line 102

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

#关系Association::BelongsTo::Proxy

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

返回:

  • ( Association::BelongsTo::Proxy )

    代理类。



95
96
97
# File 'lib/mongoid/association/referenced/belongs_to.rb', line 95

def 关系
  代理
end

# relation_complementsArray< Mongoid::Association::Relatable >

关联补充列表。

返回:



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

def lation_complements
  @relation_complements ||= [ 有很多, 有一个 ].冻结
end

# 解析器 nil | Mongoid::ModelResolver

返回对象将多态类型引用转换为类对象的对象,反之亦然。 这是通过定义关联时提供的 ':polyphic' 选项获得的。

请参阅 Mongoid::ModelResolver.resolver 了解此处如何解释 ':poly态ic` 选项。

返回:

引发:

  • 如果给定标识符下没有注册此类解析程序,则出现 KeyError 错误。



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

def 解析器
  @resolver ||= Mongoid::ModelResolver.解析器(@options[:poly态])
end

#scopeProc | Symbol | nil

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

返回:

  • (Proc | Symbol | nil)

    关联范围(如果有)。



153
154
155
# File 'lib/mongoid/association/referenced/belongs_to.rb', line 153

def 范围
  @options[:scope]
end

# setup!self

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

返回:

  • ( self )


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

def setup!
  setup_instance_methods!
  @owner_class.aliased_fields[名称.to_s] = foreign_key
  self
end

#stores_foreign_key?true

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

返回:

  • ( true )

    始终为 true。



72
# File 'lib/mongoid/association/referenced/belongs_to.rb', line 72

def store_foreign_key? true end

# validation_defaultfalse

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

返回:

  • ( false )

    始终为 false。



82
# File 'lib/mongoid/association/referenced/belongs_to.rb', line 82

def validation_default false end