Module: Mongoid::Association::Options
Overview
Options context used for all association types.
Instance Attribute Summary
Instance Method Summary
Instance Attribute Details
#autobuilding? ⇒ true | false
Whether the association is autobuilding.
[ GitHub ]
# File 'lib/mongoid/association/options.rb', line 38
def autobuilding?
!!@options[:autobuild]
end
#autosave ⇒ true | 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.
[ GitHub ]
# File 'lib/mongoid/association/options.rb', line 85
def autosave
!!@options[:autosave]
end
#autosave?
[ GitHub ]
# File 'lib/mongoid/association/options.rb', line 88
alias autosave? autosave
#cascading_callbacks? ⇒ true | false
Whether the association has callbacks cascaded down from the parent.
[ GitHub ]
# File 'lib/mongoid/association/options.rb', line 107
def cascading_callbacks?
!!@options[:cascade_callbacks]
end
#counter_cached? ⇒ true | false
Whether the association is counter-cached.
[ GitHub ]
# File 'lib/mongoid/association/options.rb', line 93
def counter_cached?
!!@options[:counter_cache]
end
#cyclic? ⇒ true | false
Is the association cyclic.
[ GitHub ]
# File 'lib/mongoid/association/options.rb', line 62
def cyclic?
!!@options[:cyclic]
end
#fallback ⇒ Object | nil
Invokes the :fallback Proc and returns the null object that stands in
for the association when its actual value is nil. The Proc is invoked
on every access; identity is the user's responsibility (return a fresh
instance, a shared constant, or whatever the Proc chooses).
[ GitHub ]
# File 'lib/mongoid/association/options.rb', line 48
def fallback
@options[:fallback]&.call
end
#fallback? ⇒ true | false
Whether the association has a :fallback (null object) option set.
[ GitHub ]
# File 'lib/mongoid/association/options.rb', line 55
def fallback?
!@options[:fallback].nil?
end
#forced_nil_inverse? ⇒ false
Whether the association has forced nil inverse (So no foreign keys are saved).
[ GitHub ]
# File 'lib/mongoid/association/options.rb', line 119
def forced_nil_inverse?
false
end
#indexed? ⇒ true | false
Whether to index the primary or foreign key field.
[ GitHub ]
# File 'lib/mongoid/association/options.rb', line 31
def indexed?
@indexed ||= !!@options[:index]
end
#polymorphic? ⇒ true | false
Whether this association is polymorphic.
[ GitHub ]
# File 'lib/mongoid/association/options.rb', line 100
def polymorphic?
false
end
#touchable? ⇒ true | false
This method is for internal use only.
Whether the association object should be automatically touched
when its inverse object is updated.
[ GitHub ]
# File 'lib/mongoid/association/options.rb', line 142
def touchable?
!!@options[:touch]
end
Instance Method Details
Returns the name of the parent to a polymorphic child.
[ GitHub ]
# File 'lib/mongoid/association/options.rb', line 10
def as
@options[:as]
end
#dependent ⇒ String
Specify what happens to the associated object when the owner is destroyed.
[ GitHub ]
# File 'lib/mongoid/association/options.rb', line 17
def dependent
@options[:dependent]
end
#inverse_of ⇒ String
The name the owning object uses to refer to this association.
[ GitHub ]
# File 'lib/mongoid/association/options.rb', line 69
def inverse_of
@options[:inverse_of]
end
The custom sorting options on the association.
[ GitHub ]
# File 'lib/mongoid/association/options.rb', line 24
def order
@options[:order]
end
::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.
[ GitHub ]
# File 'lib/mongoid/association/options.rb', line 77
def primary_key
@primary_key ||= @options[:primary_key] ? @options[:primary_key].to_s : Relatable::PRIMARY_KEY_DEFAULT
end
#store_as ⇒ nil
[ GitHub ]
# File 'lib/mongoid/association/options.rb', line 114
def store_as; end
#touch_field ⇒ nil
The field for saving the associated object's type.
[ GitHub ]
# File 'lib/mongoid/association/options.rb', line 131
def touch_field
@touch_field ||= options[:touch] if options[:touch].is_a?(String) || options[:touch].is_a?(Symbol)
end
#type ⇒ nil
The field for saving the associated object's type.
[ GitHub ]
# File 'lib/mongoid/association/options.rb', line 126
def type; end