模块:Mongoid::Association::Options

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

Overview

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

实例方法摘要折叠

实例方法详细信息

#asString | Symbol

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

返回:

  • ( string | Symbol )

    名称。



13
14
15
# File 'lib/mongoid/association/options.rb', line 13

def 作为
  @options[:as]
end

# autobuild?true | false

关联是否为自动构建。

返回:

  • ( true | false )


41
42
43
# File 'lib/mongoid/association/options.rb', line 41

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

# autosavetrue | false也称为: autosave?

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

返回:

  • ( true | false )

    自动保存选项。



71
72
73
# File 'lib/mongoid/association/options.rb', line 71

def autosave
  !!@options[:autosave]
end

# cascading_callbacks?true | false

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

返回:

  • ( true | false )

    回调是否级联。



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

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

# counter_cached?true | false

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

返回:

  • ( true | false )


79
80
81
# File 'lib/mongoid/association/options.rb', line 79

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

#循环?true | false

关联是否为循环关联。

返回:

  • ( true | false )

    关联是否为循环关联。



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

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

#依赖string

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

返回:

  • ( string )

    依赖选项。



20
21
22
# File 'lib/mongoid/association/options.rb', line 20

def 依赖
  @options[:depend]
end

#forced_nil_inverse?false

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

返回:

  • ( false )

    默认为 false。



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

def forced_nil_inverse? false end

#已索引?true | false

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

返回:

  • ( true | false )


34
35
36
# File 'lib/mongoid/association/options.rb', line 34

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

# inverse_ofstring

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

返回:

  • ( string )

    inverse_of 选项。



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

def inverse_of
  @options[:inverse_of]
end

#orderCriteria::Queryable::Key

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

返回:



27
28
29
# File 'lib/mongoid/association/options.rb', line 27

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

#多态?true | false

此关联是否为多态。

返回:

  • ( true | false )

    该关联是否是多态的。



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

def 多态? false end

#primary_key符号 | string

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

返回:

  • (符号 | string )

    主键。



63
64
65
# File 'lib/mongoid/association/options.rb', line 63

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

#store_asnil

store_as 选项。

返回:

  • ( nil )

    默认为零。



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

def store_as end

# touch_fieldnil

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

返回:

  • ( nil )

    默认为零。



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

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

# touchable?true | false

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

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

返回:

  • ( true | false )

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



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

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

#typenil

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

返回:

  • ( nil )

    默认为零。



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

def 类型 end