Module: Mongoid::Association
- Extended by:
- ActiveSupport::Concern
- Includes:
- Accessors, Builders, Depending, Embedded::Cyclic, Macros, Referenced::AutoSave, Referenced::CounterCache, Referenced::Syncable, Reflections
- Included in:
- Composable
- Defined in:
- build/mongoid-7.3/lib/mongoid/association.rb,
build/mongoid-7.3/lib/mongoid/association/one.rb,
build/mongoid-7.3/lib/mongoid/association/many.rb,
build/mongoid-7.3/lib/mongoid/association/proxy.rb,
build/mongoid-7.3/lib/mongoid/association/macros.rb,
build/mongoid-7.3/lib/mongoid/association/nested.rb,
build/mongoid-7.3/lib/mongoid/association/options.rb,
build/mongoid-7.3/lib/mongoid/association/bindable.rb,
build/mongoid-7.3/lib/mongoid/association/builders.rb,
build/mongoid-7.3/lib/mongoid/association/accessors.rb,
build/mongoid-7.3/lib/mongoid/association/depending.rb,
build/mongoid-7.3/lib/mongoid/association/relatable.rb,
build/mongoid-7.3/lib/mongoid/association/nested/one.rb,
build/mongoid-7.3/lib/mongoid/association/marshalable.rb,
build/mongoid-7.3/lib/mongoid/association/nested/many.rb,
build/mongoid-7.3/lib/mongoid/association/reflections.rb,
build/mongoid-7.3/lib/mongoid/association/constrainable.rb,
build/mongoid-7.3/lib/mongoid/association/eager_loadable.rb,
build/mongoid-7.3/lib/mongoid/association/embedded/cyclic.rb,
build/mongoid-7.3/lib/mongoid/association/referenced/eager.rb,
build/mongoid-7.3/lib/mongoid/association/embedded/batchable.rb,
build/mongoid-7.3/lib/mongoid/association/referenced/has_one.rb,
build/mongoid-7.3/lib/mongoid/association/embedded/embeds_one.rb,
build/mongoid-7.3/lib/mongoid/association/referenced/has_many.rb,
build/mongoid-7.3/lib/mongoid/association/referenced/syncable.rb,
build/mongoid-7.3/lib/mongoid/association/embedded/embedded_in.rb,
build/mongoid-7.3/lib/mongoid/association/embedded/embeds_many.rb,
build/mongoid-7.3/lib/mongoid/association/referenced/auto_save.rb,
build/mongoid-7.3/lib/mongoid/association/referenced/belongs_to.rb,
build/mongoid-7.3/lib/mongoid/association/nested/nested_buildable.rb,
build/mongoid-7.3/lib/mongoid/association/referenced/counter_cache.rb,
build/mongoid-7.3/lib/mongoid/association/referenced/has_one/eager.rb,
build/mongoid-7.3/lib/mongoid/association/referenced/has_one/proxy.rb,
build/mongoid-7.3/lib/mongoid/association/embedded/embeds_one/proxy.rb,
build/mongoid-7.3/lib/mongoid/association/referenced/has_many/eager.rb,
build/mongoid-7.3/lib/mongoid/association/referenced/has_many/proxy.rb,
build/mongoid-7.3/lib/mongoid/association/embedded/embedded_in/proxy.rb,
build/mongoid-7.3/lib/mongoid/association/embedded/embeds_many/proxy.rb,
build/mongoid-7.3/lib/mongoid/association/referenced/has_one/binding.rb,
build/mongoid-7.3/lib/mongoid/association/embedded/embeds_one/binding.rb,
build/mongoid-7.3/lib/mongoid/association/referenced/belongs_to/eager.rb,
build/mongoid-7.3/lib/mongoid/association/referenced/belongs_to/proxy.rb,
build/mongoid-7.3/lib/mongoid/association/referenced/has_many/binding.rb,
build/mongoid-7.3/lib/mongoid/association/embedded/embedded_in/binding.rb,
build/mongoid-7.3/lib/mongoid/association/embedded/embeds_many/binding.rb,
build/mongoid-7.3/lib/mongoid/association/referenced/has_one/buildable.rb,
build/mongoid-7.3/lib/mongoid/association/embedded/embeds_one/buildable.rb,
build/mongoid-7.3/lib/mongoid/association/referenced/belongs_to/binding.rb,
build/mongoid-7.3/lib/mongoid/association/referenced/has_many/buildable.rb,
build/mongoid-7.3/lib/mongoid/association/embedded/embedded_in/buildable.rb,
build/mongoid-7.3/lib/mongoid/association/embedded/embeds_many/buildable.rb,
build/mongoid-7.3/lib/mongoid/association/referenced/has_many/enumerable.rb,
build/mongoid-7.3/lib/mongoid/association/referenced/belongs_to/buildable.rb,
build/mongoid-7.3/lib/mongoid/association/referenced/has_one/nested_builder.rb,
build/mongoid-7.3/lib/mongoid/association/referenced/has_and_belongs_to_many.rb,
build/mongoid-7.3/lib/mongoid/association/referenced/has_and_belongs_to_many/eager.rb,
build/mongoid-7.3/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb,
build/mongoid-7.3/lib/mongoid/association/referenced/has_and_belongs_to_many/binding.rb,
build/mongoid-7.3/lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb
Defined Under Namespace
Modules: Accessors, Bindable, Builders, Constrainable, Depending, EagerLoadable, Embedded, Macros, Marshalable, Nested, Options, Referenced, Reflections, Relatable Classes: Many, One, Proxy
Constant Summary collapse
- MACRO_MAPPING =
Map the macros to their corresponding Association classes.
{ embeds_one: Association::Embedded::EmbedsOne, embeds_many: Association::Embedded::EmbedsMany, embedded_in: Association::Embedded::EmbeddedIn, has_one: Association::Referenced::HasOne, has_many: Association::Referenced::HasMany, has_and_belongs_to_many: Association::Referenced::HasAndBelongsToMany, belongs_to: Association::Referenced::BelongsTo, }.freeze
Constants included from Depending
Instance Attribute Summary collapse
-
#_association ⇒ Object
Returns the value of attribute _association.
Instance Method Summary collapse
-
#association_name ⇒ Symbol
Get the association name for this document.
-
#embedded? ⇒ true, false
Determine if the document itself is embedded in another document via the proper channels.
-
#embedded_many? ⇒ true, false
Determine if the document is part of an embeds_many association.
-
#embedded_one? ⇒ true, false
Determine if the document is part of an embeds_one association.
-
#referenced_many? ⇒ true, false
Determine if the document is part of an references_many association.
-
#referenced_one? ⇒ true, false
Determine if the document is part of an references_one association.
-
#reload_relations ⇒ Hash
Convenience method for iterating through the loaded associations and reloading them.
Methods included from Reflections
#reflect_on_all_association, #reflect_on_association
Methods included from Macros
Methods included from Depending
#apply_destroy_dependencies!, define_dependency!, validate!
Methods included from Accessors
#__build__, #create_relation, #reset_relation_criteria, #set_relation
Methods included from Referenced::Syncable
#_syncable?, #_synced, #_synced?, #remove_inverse_keys, #update_inverse_keys
Methods included from Referenced::CounterCache
define_callbacks!, #reset_counters
Methods included from Referenced::AutoSave
#__autosaving__, #autosaved?, #changed_for_autosave?, define_autosave!
Instance Attribute Details
#_association ⇒ Object
Returns the value of attribute _association.
49 50 51 |
# File 'build/mongoid-7.3/lib/mongoid/association.rb', line 49 def _association @_association end |
Instance Method Details
#association_name ⇒ Symbol
Get the association name for this document. If no association was defined
an error will be raised.
104 105 106 107 |
# File 'build/mongoid-7.3/lib/mongoid/association.rb', line 104 def association_name raise Errors::NoMetadata.new(self.class.name) unless _association _association.name end |
#embedded? ⇒ true, false
Determine if the document itself is embedded in another document via the proper channels. (If it has a parent document.)
65 66 67 |
# File 'build/mongoid-7.3/lib/mongoid/association.rb', line 65 def @embedded ||= (cyclic ? _parent.present? : self.class.) end |
#embedded_many? ⇒ true, false
Determine if the document is part of an embeds_many association.
77 78 79 |
# File 'build/mongoid-7.3/lib/mongoid/association.rb', line 77 def _association && _association.is_a?(Association::Embedded::EmbedsMany) end |
#embedded_one? ⇒ true, false
Determine if the document is part of an embeds_one association.
89 90 91 |
# File 'build/mongoid-7.3/lib/mongoid/association.rb', line 89 def _association && _association.is_a?(Association::Embedded::EmbedsOne) end |
#referenced_many? ⇒ true, false
Determine if the document is part of an references_many association.
117 118 119 |
# File 'build/mongoid-7.3/lib/mongoid/association.rb', line 117 def referenced_many? _association && _association.is_a?(Association::Referenced::HasMany) end |
#referenced_one? ⇒ true, false
Determine if the document is part of an references_one association.
129 130 131 |
# File 'build/mongoid-7.3/lib/mongoid/association.rb', line 129 def referenced_one? _association && _association.is_a?(Association::Referenced::HasOne) end |
#reload_relations ⇒ Hash
Convenience method for iterating through the loaded associations and reloading them.
142 143 144 145 146 147 148 149 150 |
# File 'build/mongoid-7.3/lib/mongoid/association.rb', line 142 def reload_relations relations.each_pair do |name, | if instance_variable_defined?("@_#{name}") if _parent.nil? || instance_variable_get("@_#{name}") != _parent remove_instance_variable("@_#{name}") end end end end |