Module: Mongoid::Association::Options
- Included in:
- Relatable
- Defined in:
- lib/mongoid/association/options.rb
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 relation has callbacks cascaded down from the parent.
-
#counter_cached? ⇒ true, false
Whether the association is counter-cached.
-
#cyclic? ⇒ true, false
Is the relation cyclic.
-
#dependent ⇒ String
Specify what happens to the associated object when the owner is destroyed.
-
#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 relation.
-
#order ⇒ Criteria::Queryable::Key
The custom sorting options on the relation.
-
#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.
-
#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.
11 12 13 |
# File 'lib/mongoid/association/options.rb', line 11 def as @options[:as] end |
#autobuilding? ⇒ true, false
Whether the association is autobuilding.
47 48 49 |
# File 'lib/mongoid/association/options.rb', line 47 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.
85 86 87 |
# File 'lib/mongoid/association/options.rb', line 85 def autosave !!@options[:autosave] end |
#cascading_callbacks? ⇒ true, false
Whether the relation has callbacks cascaded down from the parent.
111 112 113 |
# File 'lib/mongoid/association/options.rb', line 111 def cascading_callbacks? !!@options[:cascade_callbacks] end |
#counter_cached? ⇒ true, false
Whether the association is counter-cached.
95 96 97 |
# File 'lib/mongoid/association/options.rb', line 95 def counter_cached? !!@options[:counter_cache] end |
#cyclic? ⇒ true, false
Is the relation cyclic.
56 57 58 |
# File 'lib/mongoid/association/options.rb', line 56 def cyclic? !!@options[:cyclic] end |
#dependent ⇒ String
Specify what happens to the associated object when the owner is destroyed.
20 21 22 |
# File 'lib/mongoid/association/options.rb', line 20 def dependent @options[:dependent] end |
#forced_nil_inverse? ⇒ false
Whether the association has forced nil inverse (So no foreign keys are saved).
127 |
# File 'lib/mongoid/association/options.rb', line 127 def forced_nil_inverse?; false; end |
#indexed? ⇒ true, false
Whether to index the primary or foreign key field.
38 39 40 |
# File 'lib/mongoid/association/options.rb', line 38 def indexed? @indexed ||= !!@options[:index] end |
#inverse_of ⇒ String
The name the owning object uses to refer to this relation.
65 66 67 |
# File 'lib/mongoid/association/options.rb', line 65 def inverse_of @options[:inverse_of] end |
#order ⇒ Criteria::Queryable::Key
The custom sorting options on the relation.
29 30 31 |
# File 'lib/mongoid/association/options.rb', line 29 def order @options[:order] end |
#polymorphic? ⇒ true, false
Whether this association is polymorphic.
104 |
# File 'lib/mongoid/association/options.rb', line 104 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.
75 76 77 |
# 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 ⇒ nil
The store_as option.
120 |
# File 'lib/mongoid/association/options.rb', line 120 def store_as; end |
#touch_field ⇒ nil
The field for saving the associated object’s type.
141 142 143 |
# File 'lib/mongoid/association/options.rb', line 141 def touch_field @touch_field ||= [:touch] if ([:touch].is_a?(String) || [:touch].is_a?(Symbol)) end |
#type ⇒ nil
The field for saving the associated object’s type.
134 |
# File 'lib/mongoid/association/options.rb', line 134 def type; end |