Class: Mongoid::Association::Embedded::EmbedsMany
- Inherits:
-
Object
- Object
- Mongoid::Association::Embedded::EmbedsMany
- Defined in:
- build/mongoid-7.3/lib/mongoid/association/embedded/embeds_many.rb,
build/mongoid-7.3/lib/mongoid/association/embedded/embeds_many/proxy.rb,
build/mongoid-7.3/lib/mongoid/association/embedded/embeds_many/binding.rb,
build/mongoid-7.3/lib/mongoid/association/embedded/embeds_many/buildable.rb
Overview
The EmbedsMany type association.
Defined Under Namespace
Modules: Buildable Classes: Binding, Proxy
Constant Summary collapse
- ASSOCIATION_OPTIONS =
The options available for this type of association, in addition to the common ones.
[ :as, :cascade_callbacks, :cyclic, :order, :store_as, :before_add, :after_add, :before_remove, :after_remove ]
- VALID_OPTIONS =
The complete list of valid options for this association, including the shared ones.
(ASSOCIATION_OPTIONS + SHARED_OPTIONS).freeze
Constants included from Relatable
Relatable::PRIMARY_KEY_DEFAULT, Relatable::SHARED_OPTIONS
Instance Attribute Summary
Attributes included from Relatable
Instance Method Summary collapse
-
#criteria(base, target) ⇒ Object
Get a criteria object for searching given a parent and children documents.
-
#embedded? ⇒ true
Is this association type embedded?.
-
#key ⇒ String
The key that is used to get the attributes for the associated object.
-
#nested_builder(attributes, options) ⇒ Association::Nested::Many
The nested builder object.
-
#path(document) ⇒ Mongoid::Atomic::Paths::Embedded::Many
Get the path calculator for the supplied document.
-
#polymorphic? ⇒ true, false
Is this association polymorphic?.
-
#primary_key ⇒ nil
The primary key.
-
#relation ⇒ Association::Embedded::EmbedsMany::Proxy
Get the association proxy class for this association type.
-
#setup! ⇒ self
Setup the instance methods, fields, etc.
-
#store_as ⇒ String
The field key used to store the list of association objects.
-
#stores_foreign_key? ⇒ false
Does this association type store the foreign key?.
-
#type ⇒ String?
The field used to store the type of the related object.
-
#validation_default ⇒ true
Get the default validation setting for the association.
Methods included from Buildable
Methods included from Relatable
#==, #bindable?, #counter_cache_column_name, #create_relation, #destructive?, #extension, #foreign_key_check, #foreign_key_setter, #get_callbacks, #initialize, #inverse, #inverse_association, #inverse_class, #inverse_class_name, #inverse_setter, #inverse_type, #inverse_type_setter, #inverses, #relation_class, #relation_class_name, #setter, #type_setter, #validate?
Methods included from Options
#as, #autobuilding?, #autosave, #cascading_callbacks?, #counter_cached?, #cyclic?, #dependent, #forced_nil_inverse?, #indexed?, #inverse_of, #order, #touch_field
Methods included from Constrainable
Instance Method Details
#criteria(base, target) ⇒ Object
Get a criteria object for searching given a parent and children documents.
167 168 169 170 171 172 173 174 |
# File 'build/mongoid-7.3/lib/mongoid/association/embedded/embeds_many.rb', line 167 def criteria(base, target) criterion = klass.scoped criterion. = true criterion.documents = target criterion.parent_document = base criterion.association = self apply_ordering(criterion) end |
#embedded? ⇒ true
Is this association type embedded?
80 |
# File 'build/mongoid-7.3/lib/mongoid/association/embedded/embeds_many.rb', line 80 def ; true; end |
#key ⇒ String
The key that is used to get the attributes for the associated object.
71 72 73 |
# File 'build/mongoid-7.3/lib/mongoid/association/embedded/embeds_many.rb', line 71 def key store_as.to_s end |
#nested_builder(attributes, options) ⇒ Association::Nested::Many
The nested builder object.
142 143 144 |
# File 'build/mongoid-7.3/lib/mongoid/association/embedded/embeds_many.rb', line 142 def nested_builder(attributes, ) Nested::Many.new(self, attributes, ) end |
#path(document) ⇒ Mongoid::Atomic::Paths::Embedded::Many
Get the path calculator for the supplied document.
157 158 159 |
# File 'build/mongoid-7.3/lib/mongoid/association/embedded/embeds_many.rb', line 157 def path(document) Mongoid::Atomic::Paths::Embedded::Many.new(document) end |
#polymorphic? ⇒ true, false
Is this association polymorphic?
119 120 121 |
# File 'build/mongoid-7.3/lib/mongoid/association/embedded/embeds_many.rb', line 119 def polymorphic? @polymorphic ||= !!@options[:as] end |
#primary_key ⇒ nil
The primary key
103 |
# File 'build/mongoid-7.3/lib/mongoid/association/embedded/embeds_many.rb', line 103 def primary_key; end |
#relation ⇒ Association::Embedded::EmbedsMany::Proxy
Get the association proxy class for this association type.
110 111 112 |
# File 'build/mongoid-7.3/lib/mongoid/association/embedded/embeds_many.rb', line 110 def relation Proxy end |
#setup! ⇒ self
Setup the instance methods, fields, etc. on the association owning class.
50 51 52 53 54 55 |
# File 'build/mongoid-7.3/lib/mongoid/association/embedded/embeds_many.rb', line 50 def setup! setup_instance_methods! @owner_class. = @owner_class..merge(name => self) @owner_class.aliased_fields[name.to_s] = store_as if store_as self end |
#store_as ⇒ String
The field key used to store the list of association objects.
62 63 64 |
# File 'build/mongoid-7.3/lib/mongoid/association/embedded/embeds_many.rb', line 62 def store_as @store_as ||= (@options[:store_as].try(:to_s) || name.to_s) end |
#stores_foreign_key? ⇒ false
Does this association type store the foreign key?
98 |
# File 'build/mongoid-7.3/lib/mongoid/association/embedded/embeds_many.rb', line 98 def stores_foreign_key?; false; end |
#type ⇒ String?
Only relevant if the association is polymorphic.
The field used to store the type of the related object.
130 131 132 |
# File 'build/mongoid-7.3/lib/mongoid/association/embedded/embeds_many.rb', line 130 def type @type ||= "#{as}_type" if polymorphic? end |
#validation_default ⇒ true
Get the default validation setting for the association. Determines if by default a validates associated will occur.
91 |
# File 'build/mongoid-7.3/lib/mongoid/association/embedded/embeds_many.rb', line 91 def validation_default; true; end |