Module: Mongoid::Association::Options

Included in:
Relatable
Defined in:
build/mongoid-7.3/lib/mongoid/association/options.rb

Instance Method Summary collapse

Instance Method Details

#asString, Symbol

Returns the name of the parent to a polymorphic child.

Returns:

  • (String, Symbol)

    The name.

Since:

  • 7.0



14
15
16
# File 'build/mongoid-7.3/lib/mongoid/association/options.rb', line 14

def as
  @options[:as]
end

#autobuilding?true, false

Whether the association is autobuilding.

Returns:

  • (true, false)

Since:

  • 7.0



50
51
52
# File 'build/mongoid-7.3/lib/mongoid/association/options.rb', line 50

def autobuilding?
  !!@options[:autobuild]
end

#autosavetrue, false Also known as: autosave?

Options to save any loaded members and destroy members that are marked for destruction when the parent object is saved.

Returns:

  • (true, false)

    The autosave option.

Since:

  • 7.0



88
89
90
# File 'build/mongoid-7.3/lib/mongoid/association/options.rb', line 88

def autosave
  !!@options[:autosave]
end

#cascading_callbacks?true, false

Whether the association has callbacks cascaded down from the parent.

Returns:

  • (true, false)

    Whether callbacks are cascaded.

Since:

  • 7.0



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

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

#counter_cached?true, false

Whether the association is counter-cached.

Returns:

  • (true, false)

Since:

  • 7.0



98
99
100
# File 'build/mongoid-7.3/lib/mongoid/association/options.rb', line 98

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

#cyclic?true, false

Is the association cyclic.

Returns:

  • (true, false)

    Whether the association is cyclic.

Since:

  • 7.0



59
60
61
# File 'build/mongoid-7.3/lib/mongoid/association/options.rb', line 59

def cyclic?
  !!@options[:cyclic]
end

#dependentString

Specify what happens to the associated object when the owner is destroyed.

Returns:

  • (String)

    The dependent option.

Since:

  • 7.0



23
24
25
# File 'build/mongoid-7.3/lib/mongoid/association/options.rb', line 23

def dependent
  @options[:dependent]
end

#forced_nil_inverse?false

Whether the association has forced nil inverse (So no foreign keys are saved).

Returns:

  • (false)

    Default is false.

Since:

  • 7.0



130
# File 'build/mongoid-7.3/lib/mongoid/association/options.rb', line 130

def forced_nil_inverse?; false; end

#indexed?true, false

Whether to index the primary or foreign key field.

Returns:

  • (true, false)

Since:

  • 7.0



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

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

#inverse_ofString

The name the owning object uses to refer to this association.

Returns:

  • (String)

    The inverse_of option.

Since:

  • 7.0



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

def inverse_of
  @options[:inverse_of]
end

#orderCriteria::Queryable::Key

The custom sorting options on the association.

Returns:

Since:

  • 7.0



32
33
34
# File 'build/mongoid-7.3/lib/mongoid/association/options.rb', line 32

def order
  @options[:order]
end

#polymorphic?true, false

Whether this association is polymorphic.

Returns:

  • (true, false)

    Whether the association is polymorphic.

Since:

  • 7.0



107
# File 'build/mongoid-7.3/lib/mongoid/association/options.rb', line 107

def polymorphic?; false; end

#primary_keySymbol, String

Mongoid assumes that the field used to hold the primary key of the association is id. You can override this and explicitly specify the primary key with the :primary_key option.

Returns:

  • (Symbol, String)

    The primary key.

Since:

  • 7.0



78
79
80
# File 'build/mongoid-7.3/lib/mongoid/association/options.rb', line 78

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

#store_asnil

The store_as option.

Returns:

  • (nil)

    Default is nil.

Since:

  • 7.0



123
# File 'build/mongoid-7.3/lib/mongoid/association/options.rb', line 123

def store_as; end

#touch_fieldnil

The field for saving the associated object’s type.

Returns:

  • (nil)

    Default is nil.

Since:

  • 7.0



144
145
146
# File 'build/mongoid-7.3/lib/mongoid/association/options.rb', line 144

def touch_field
  @touch_field ||= options[:touch] if (options[:touch].is_a?(String) || options[:touch].is_a?(Symbol))
end

#typenil

The field for saving the associated object’s type.

Returns:

  • (nil)

    Default is nil.

Since:

  • 7.0



137
# File 'build/mongoid-7.3/lib/mongoid/association/options.rb', line 137

def type; end