模块:Mongoid::Association::Options

包含在:
Relatable
定义于:
lib/mongoid/association/options.rb

Overview

用于所有关联类型的选项上下文。

实例方法摘要折叠

实例方法详细信息

#asString | Symbol

返回多态子文档的父文档名称。

返回:

  • ( string | Symbol )

    名称。



10
11
12
# File 'lib/mongoid/association/options.rb', line 10

def 作为
  @options[:as]
end

# autobuild?true | false

关联是否为自动构建。

返回:

  • ( true | false )


38
39
40
# File 'lib/mongoid/association/options.rb', line 38

def 自动构建?
  !!@options[:autobuild]
end

# autosavetrue | false也称为: autosave?

用于在保存父对象时保存任何已加载成员并销毁标记为销毁的成员的选项。

返回:

  • ( true | false )

    自动保存选项。



68
69
70
# File 'lib/mongoid/association/options.rb', line 68

def autosave
  !!@options[:autosave]
end

# cascading_callbacks?true | false

关联是否具有从父级向下级联的回调。

返回:

  • ( true | false )

    回调是否级联。



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

def cascading_callbacks?
  !!@options[:cascade_callbacks]
end

# counter_cached?true | false

是否对关联进行计数器缓存。

返回:

  • ( true | false )


76
77
78
# File 'lib/mongoid/association/options.rb', line 76

def counter_cached?
  !!@options[:counter_cache]
end

#循环?true | false

关联是否为循环关联。

返回:

  • ( true | false )

    关联是否为循环关联。



45
46
47
# File 'lib/mongoid/association/options.rb', line 45

def 循环?
  !!@options[:循环]
end

#依赖string

指定当所有者被销毁时关联对象会发生什么情况。

返回:

  • ( string )

    依赖选项。



17
18
19
# File 'lib/mongoid/association/options.rb', line 17

def 依赖
  @options[:depend]
end

#forced_nil_inverse?false

关联是否强制执行 nil inverse(因此不保存外键)。

返回:

  • ( false )

    默认为 false。



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

def forced_nil_inverse?
  false
end

#已索引?true | false

是否对主节点 (primary node in the replica set)键字段或外键字段进行索引。

返回:

  • ( true | false )


31
32
33
# File 'lib/mongoid/association/options.rb', line 31

def 索引?
  @indexed ||= !!@options[:index]
end

# inverse_ofstring

所属对象用来引用此关联的名称。

返回:

  • ( string )

    inverse_of 选项。



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

def inverse_of
  @options[:inverse_of]
end

#orderCriteria::Queryable::Key

关联上的自定义排序选项。

返回:



24
25
26
# File 'lib/mongoid/association/options.rb', line 24

def 来自一个购物车应用的order文档,
  @options[:order]
end

#多态?true | false

此关联是否为多态。

返回:

  • ( true | false )

    该关联是否是多态的。



83
84
85
# File 'lib/mongoid/association/options.rb', line 83

def 多态?
  false
end

#primary_key符号 | string

Mongoid 假定用于保存关联主键的字段是ID 。 您可以覆盖此设置并使用 :primary_key 选项显式指定主键。

返回:

  • (符号 | string )

    主键。



60
61
62
# File 'lib/mongoid/association/options.rb', line 60

def primary_key
  @primary_key ||= @options[:primary_key] ? @options[:primary_key].to_s : Relatable::PRIMARY_KEY_DEFAULT
end

#store_asnil

store_as 选项。

返回:

  • ( nil )

    默认为零。



97
# File 'lib/mongoid/association/options.rb', line 97

def store_as end

# touch_fieldnil

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

返回:

  • ( nil )

    默认为零。



114
115
116
# File 'lib/mongoid/association/options.rb', line 114

def touch_field
  @touch_field ||= 选项[:touch] if 选项[:touch].is_a?(字符串) || 选项[:touch].is_a?(符号)
end

# touchable?true | false

此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。

更新反向对象时,是否应自动触及关联对象。

返回:

  • ( true | false )

    如果自动触及此关联,则返回 true,否则返回 false。 默认为 false。



125
126
127
# File 'lib/mongoid/association/options.rb', line 125

def touchable?
  !!@options[:touch]
end

#typenil

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

返回:

  • ( nil )

    默认为零。



109
# File 'lib/mongoid/association/options.rb', line 109

def 类型 end