123456789_123456789_123456789_123456789_123456789_

Module: Mongoid::Association::Options

Overview

Options context used for all association types.

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#autobuilding?true | false (readonly)

Whether the association is autobuilding.

[ GitHub ]

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

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

#autosavetrue | false (readonly) 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.

[ GitHub ]

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

def autosave
  !!@options[:autosave]
end

#autosave? (readonly)

Alias for #autosave.

[ GitHub ]

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

alias :autosave? :autosave

#cascading_callbacks?true | false (readonly)

Whether the association has callbacks cascaded down from the parent.

Returns:

  • (true | false)

    Whether callbacks are cascaded.

[ GitHub ]

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

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

#counter_cached?true | false (readonly)

Whether the association is counter-cached.

[ GitHub ]

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

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

#cyclic?true | false (readonly)

Is the association cyclic.

Returns:

  • (true | false)

    Whether the association is cyclic.

[ GitHub ]

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

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

#forced_nil_inverse?false (readonly)

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

Returns:

  • (false)

    Default is false.

[ GitHub ]

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

def forced_nil_inverse?; false; end

#indexed?true | false (readonly)

Whether to index the primary or foreign key field.

[ GitHub ]

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

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

#polymorphic?true | false (readonly)

Whether this association is polymorphic.

Returns:

  • (true | false)

    Whether the association is polymorphic.

[ GitHub ]

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

def polymorphic?; false; end

#touchable?true | false (readonly)

This method is for internal use only.

Whether the association object should be automatically touched when its inverse object is updated.

Returns:

  • (true | false)

    returns true if this association is automatically touched, false otherwise. The default is false.

[ GitHub ]

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

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

Instance Method Details

#asString | Symbol

Returns the name of the parent to a polymorphic child.

Returns:

[ GitHub ]

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

def as
  @options[:as]
end

#dependentString

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

Returns:

  • (String)

    The dependent option.

[ GitHub ]

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

def dependent
  @options[:dependent]
end

#inverse_ofString

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

Returns:

  • (String)

    The inverse_of option.

[ GitHub ]

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

def inverse_of
  @options[:inverse_of]
end

#orderCriteria::Queryable::Key

The custom sorting options on the association.

Returns:

[ GitHub ]

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

def order
  @options[:order]
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:

[ GitHub ]

  
# 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

The store_as option.

Returns:

  • (nil)

    Default is nil.

[ GitHub ]

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

def store_as; end

#touch_fieldnil

The field for saving the associated object’s type.

Returns:

  • (nil)

    Default is nil.

[ GitHub ]

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

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.

[ GitHub ]

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

def type; end