Module: Mongoid::Association::Options
- Included in:
- Relatable
- Defined in:
- lib/mongoid/association/options.rb
Overview
Options context used for all association types.
Instance Method Summary collapse
-
#as ⇒ String | Symbol
Returns the name of the parent to a polymorphic child.
-
#autobuilding? ⇒ true | false
Whether the association is autobuilding.
-
#autosave ⇒ true | false
(also: #autosave?)
Options to save any loaded members and destroy members that are marked for destruction when the parent object is saved.
-
#cascading_callbacks? ⇒ true | false
Whether the association has callbacks cascaded down from the parent.
-
#counter_cached? ⇒ true | false
Whether the association is counter-cached.
-
#cyclic? ⇒ true | false
Is the association cyclic.
-
#dependent ⇒ String
Specify what happens to the associated object when the owner is destroyed.
-
#fallback ⇒ Object | nil
Invokes the :fallback Proc and returns the null object that stands in for the association when its actual value is nil.
-
#fallback? ⇒ true | false
Whether the association has a :fallback (null object) option set.
-
#forced_nil_inverse? ⇒ false
Whether the association has forced nil inverse (So no foreign keys are saved).
-
#indexed? ⇒ true | false
Whether to index the primary or foreign key field.
-
#inverse_of ⇒ String
The name the owning object uses to refer to this association.
-
#order ⇒ Criteria::Queryable::Key
The custom sorting options on the association.
-
#polymorphic? ⇒ true | false
Whether this association is polymorphic.
-
#primary_key ⇒ Symbol | String
Mongoid assumes that the field used to hold the primary key of the association is id.
-
#store_as ⇒ nil
The store_as option.
-
#touch_field ⇒ nil
The field for saving the associated object's type.
-
#touchable? ⇒ true | false
private
Whether the association object should be automatically touched when its inverse object is updated.
-
#type ⇒ nil
The field for saving the associated object's type.
Instance Method Details
#as ⇒ String | Symbol
Returns the name of the parent to a polymorphic child.
10 11 12 |
# File 'lib/mongoid/association/options.rb', line 10 def as [:as] end |
#autobuilding? ⇒ true | false
Whether the association is autobuilding.
38 39 40 |
# File 'lib/mongoid/association/options.rb', line 38 def autobuilding? !![: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.
85 86 87 |
# File 'lib/mongoid/association/options.rb', line 85 def autosave !![:autosave] end |
#cascading_callbacks? ⇒ true | false
Whether the association has callbacks cascaded down from the parent.
107 108 109 |
# File 'lib/mongoid/association/options.rb', line 107 def cascading_callbacks? !![:cascade_callbacks] end |
#counter_cached? ⇒ true | false
Whether the association is counter-cached.
93 94 95 |
# File 'lib/mongoid/association/options.rb', line 93 def counter_cached? !![:counter_cache] end |
#cyclic? ⇒ true | false
Is the association cyclic.
62 63 64 |
# File 'lib/mongoid/association/options.rb', line 62 def cyclic? !![:cyclic] end |
#dependent ⇒ String
Specify what happens to the associated object when the owner is destroyed.
17 18 19 |
# File 'lib/mongoid/association/options.rb', line 17 def dependent [:dependent] 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).
48 49 50 |
# File 'lib/mongoid/association/options.rb', line 48 def fallback [:fallback]&.call end |
#fallback? ⇒ true | false
Whether the association has a :fallback (null object) option set.
55 56 57 |
# File 'lib/mongoid/association/options.rb', line 55 def fallback? ![:fallback].nil? end |
#forced_nil_inverse? ⇒ false
Whether the association has forced nil inverse (So no foreign keys are saved).
119 120 121 |
# 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.
31 32 33 |
# File 'lib/mongoid/association/options.rb', line 31 def indexed? @indexed ||= !![:index] end |
#inverse_of ⇒ String
The name the owning object uses to refer to this association.
69 70 71 |
# File 'lib/mongoid/association/options.rb', line 69 def inverse_of [:inverse_of] end |
#order ⇒ Criteria::Queryable::Key
The custom sorting options on the association.
24 25 26 |
# File 'lib/mongoid/association/options.rb', line 24 def order [:order] end |
#polymorphic? ⇒ true | false
Whether this association is polymorphic.
100 101 102 |
# File 'lib/mongoid/association/options.rb', line 100 def polymorphic? false end |
#primary_key ⇒ Symbol | 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.
77 78 79 |
# File 'lib/mongoid/association/options.rb', line 77 def primary_key @primary_key ||= [:primary_key] ? [:primary_key].to_s : Relatable::PRIMARY_KEY_DEFAULT end |
#store_as ⇒ nil
The store_as option.
114 |
# File 'lib/mongoid/association/options.rb', line 114 def store_as; end |
#touch_field ⇒ nil
The field for saving the associated object's type.
131 132 133 |
# File 'lib/mongoid/association/options.rb', line 131 def touch_field @touch_field ||= [:touch] if [:touch].is_a?(String) || [:touch].is_a?(Symbol) end |
#touchable? ⇒ true | false
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Whether the association object should be automatically touched when its inverse object is updated.
142 143 144 |
# File 'lib/mongoid/association/options.rb', line 142 def touchable? !![:touch] end |
#type ⇒ nil
The field for saving the associated object's type.
126 |
# File 'lib/mongoid/association/options.rb', line 126 def type; end |