module Mongoid::Association::Options

Public Instance Methods

as() click to toggle source

Returns the name of the parent to a polymorphic child.

@return [ String, Symbol ] The name.

@since 7.0

# File lib/mongoid/association/options.rb, line 11
def as
  @options[:as]
end
autobuilding?() click to toggle source

Whether the association is autobuilding.

@return [ true, false ]

@since 7.0

# File lib/mongoid/association/options.rb, line 47
def autobuilding?
  !!@options[:autobuild]
end
autosave() click to toggle source

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

@return [ true, false ] The autosave option.

@since 7.0

# File lib/mongoid/association/options.rb, line 85
def autosave
  !!@options[:autosave]
end
Also aliased as: autosave?
autosave?()
Alias for: autosave
cascading_callbacks?() click to toggle source

Whether the relation has callbacks cascaded down from the parent.

@return [ true, false ] Whether callbacks are cascaded.

@since 7.0

# File lib/mongoid/association/options.rb, line 111
def cascading_callbacks?
  !!@options[:cascade_callbacks]
end
counter_cached?() click to toggle source

Whether the association is counter-cached.

@return [ true, false ]

@since 7.0

# File lib/mongoid/association/options.rb, line 95
def counter_cached?
  !!@options[:counter_cache]
end
cyclic?() click to toggle source

Is the relation cyclic.

@return [ true, false ] Whether the relation is cyclic.

@since 7.0

# File lib/mongoid/association/options.rb, line 56
def cyclic?
  !!@options[:cyclic]
end
dependent() click to toggle source

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

@return [ String ] The dependent option.

@since 7.0

# File lib/mongoid/association/options.rb, line 20
def dependent
  @options[:dependent]
end
forced_nil_inverse?() click to toggle source

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

@return [ false ] Default is false.

@since 7.0

# File lib/mongoid/association/options.rb, line 127
def forced_nil_inverse?; false; end
indexed?() click to toggle source

Whether to index the primary or foreign key field.

@return [ true, false ]

@since 7.0

# File lib/mongoid/association/options.rb, line 38
def indexed?
  @indexed ||= !!@options[:index]
end
inverse_of() click to toggle source

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

@return [ String ] The inverse_of option.

@since 7.0

# File lib/mongoid/association/options.rb, line 65
def inverse_of
  @options[:inverse_of]
end
order() click to toggle source

The custom sorting options on the relation.

@return [ Criteria::Queryable::Key ] The custom sorting options.

@since 7.0

# File lib/mongoid/association/options.rb, line 29
def order
  @options[:order]
end
polymorphic?() click to toggle source

Whether this association is polymorphic.

@return [ true, false ] Whether the association is polymorphic.

@since 7.0

# File lib/mongoid/association/options.rb, line 104
def polymorphic?; false; end
primary_key() click to toggle source

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.

@return [ Symbol, String ] The primary key.

@since 7.0

# File lib/mongoid/association/options.rb, line 75
def primary_key
  @primary_key ||= @options[:primary_key] ? @options[:primary_key].to_s : Relatable::PRIMARY_KEY_DEFAULT
end
store_as() click to toggle source

The store_as option.

@return [ nil ] Default is nil.

@since 7.0

# File lib/mongoid/association/options.rb, line 120
def store_as; end
touch_field() click to toggle source

The field for saving the associated object's type.

@return [ nil ] Default is nil.

@since 7.0

# File lib/mongoid/association/options.rb, line 141
def touch_field
  @touch_field ||= options[:touch] if (options[:touch].is_a?(String) || options[:touch].is_a?(Symbol))
end
type() click to toggle source

The field for saving the associated object's type.

@return [ nil ] Default is nil.

@since 7.0

# File lib/mongoid/association/options.rb, line 134
def type; end

Private Instance Methods

touchable?() click to toggle source
# File lib/mongoid/association/options.rb, line 147
def touchable?
  !!@options[:touch]
end