# 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
module Mongoid::Association::Options
Options
context used for all association types.
Public Instance Methods
Returns the name of the parent to a polymorphic child.
@return [ String | Symbol ] The name.
# File lib/mongoid/association/options.rb, line 13 def as @options[:as] end
Whether the association is autobuilding.
@return [ true | false ]
# File lib/mongoid/association/options.rb, line 41 def autobuilding? !!@options[:autobuild] end
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.
# File lib/mongoid/association/options.rb, line 71 def autosave !!@options[:autosave] end
Whether the association has callbacks cascaded down from the parent.
@return [ true | false ] Whether callbacks are cascaded.
# File lib/mongoid/association/options.rb, line 91 def cascading_callbacks? !!@options[:cascade_callbacks] end
Whether the association is counter-cached.
@return [ true | false ]
# File lib/mongoid/association/options.rb, line 79 def counter_cached? !!@options[:counter_cache] end
Is the association cyclic.
@return [ true | false ] Whether the association is cyclic.
# File lib/mongoid/association/options.rb, line 48 def cyclic? !!@options[:cyclic] end
Specify what happens to the associated object when the owner is destroyed.
@return [ String ] The dependent option.
# File lib/mongoid/association/options.rb, line 20 def dependent @options[:dependent] end
Whether the association has forced nil inverse (So no foreign keys are saved).
@return [ false ] Default is false.
# File lib/mongoid/association/options.rb, line 103 def forced_nil_inverse?; false; end
Whether to index the primary or foreign key field.
@return [ true | false ]
# File lib/mongoid/association/options.rb, line 34 def indexed? @indexed ||= !!@options[:index] end
The name the owning object uses to refer to this association.
@return [ String ] The inverse_of
option.
# File lib/mongoid/association/options.rb, line 55 def inverse_of @options[:inverse_of] end
The custom sorting options on the association.
@return [ Criteria::Queryable::Key
] The custom sorting options.
# File lib/mongoid/association/options.rb, line 27 def order @options[:order] end
Whether this association is polymorphic.
@return [ true | false ] Whether the association is polymorphic.
# File lib/mongoid/association/options.rb, line 86 def polymorphic?; false; 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.
@return [ Symbol | String ] The primary key.
The store_as
option.
@return [ nil ] Default is nil.
# File lib/mongoid/association/options.rb, line 98 def store_as; end
The field for saving the associated object’s type.
@return [ nil ] Default is nil.
# 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
Whether the association object should be automatically touched when its inverse object is updated.
@return [ true | false ] returns true if this association is
automatically touched, false otherwise. The default is false.
@api private
# File lib/mongoid/association/options.rb, line 124 def touchable? !!@options[:touch] end
The field for saving the associated object’s type.
@return [ nil ] Default is nil.
# File lib/mongoid/association/options.rb, line 108 def type; end