Class: Mongoid::Relations::Embedded::In
- Defined in:
- lib/mongoid/relations/embedded/in.rb
Overview
This class defines the behaviour necessary to handle relations that are embedded within another relation, either as a single document or multiple documents.
Constant Summary collapse
- VALID_OPTIONS =
The allowed options when defining this relation.
[ :autobuild, :cyclic, :polymorphic, :touch ].freeze
Instance Attribute Summary
Attributes inherited from Proxy
Class Method Summary collapse
-
.builder(base, meta, object) ⇒ Builder
Return the builder that is responsible for generating the documents that will be used by this relation.
-
.embedded? ⇒ true
Returns true if the relation is an embedded one.
-
.foreign_key_suffix ⇒ nil
Returns the suffix of the foreign key field, either “_id” or “_ids”.
-
.macro ⇒ Symbol
Returns the macro for this relation.
-
.nested_builder(metadata, attributes, options) ⇒ Builder
Return the nested builder that is responsible for generating the documents that will be used by this relation.
-
.path(document) ⇒ Root
Get the path calculator for the supplied document.
-
.stores_foreign_key? ⇒ false
Tells the caller if this relation is one that stores the foreign key on its own objects.
-
.valid_options ⇒ Array<Symbol>
Get the valid options allowed with this relation.
-
.validation_default ⇒ true, false
Get the default validation setting for the relation.
Instance Method Summary collapse
-
#initialize(base, target, metadata) ⇒ In
constructor
Instantiate a new embedded_in relation.
-
#substitute(replacement) ⇒ Document?
Substitutes the supplied target documents for the existing document in the relation.
Methods inherited from One
#__evolve_object_id__, #clear, #in_memory, #respond_to?
Methods inherited from Proxy
apply_ordering, #extend_proxies, #init, #klass, #reset_unloaded, #substitutable
Methods included from Marshalable
Constructor Details
#initialize(base, target, metadata) ⇒ In
Instantiate a new embedded_in relation.
33 34 35 36 37 38 |
# File 'lib/mongoid/relations/embedded/in.rb', line 33 def initialize(base, target, ) init(base, target, ) do characterize_one(target) bind_one end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Mongoid::Relations::Proxy
Class Method Details
.builder(base, meta, object) ⇒ Builder
Return the builder that is responsible for generating the documents that will be used by this relation.
120 121 122 |
# File 'lib/mongoid/relations/embedded/in.rb', line 120 def builder(base, , object) Builders::Embedded::In.new(base, , object) end |
.embedded? ⇒ true
Returns true if the relation is an embedded one. In this case always true.
133 134 135 |
# File 'lib/mongoid/relations/embedded/in.rb', line 133 def true end |
.foreign_key_suffix ⇒ nil
Returns the suffix of the foreign key field, either “_id” or “_ids”.
145 146 147 |
# File 'lib/mongoid/relations/embedded/in.rb', line 145 def foreign_key_suffix nil end |
.macro ⇒ Symbol
Returns the macro for this relation. Used mostly as a helper in reflection.
158 159 160 |
# File 'lib/mongoid/relations/embedded/in.rb', line 158 def macro :embedded_in end |
.nested_builder(metadata, attributes, options) ⇒ Builder
Return the nested builder that is responsible for generating the documents that will be used by this relation.
184 185 186 |
# File 'lib/mongoid/relations/embedded/in.rb', line 184 def nested_builder(, attributes, ) Builders::NestedAttributes::One.new(, attributes, ) end |
.path(document) ⇒ Root
Get the path calculator for the supplied document.
198 199 200 |
# File 'lib/mongoid/relations/embedded/in.rb', line 198 def path(document) Mongoid::Atomic::Paths::Root.new(document) end |
.stores_foreign_key? ⇒ false
Tells the caller if this relation is one that stores the foreign key on its own objects.
211 212 213 |
# File 'lib/mongoid/relations/embedded/in.rb', line 211 def stores_foreign_key? false end |
.valid_options ⇒ Array<Symbol>
Get the valid options allowed with this relation.
223 224 225 |
# File 'lib/mongoid/relations/embedded/in.rb', line 223 def VALID_OPTIONS end |
.validation_default ⇒ true, false
Get the default validation setting for the relation. Determines if by default a validates associated will occur.
236 237 238 |
# File 'lib/mongoid/relations/embedded/in.rb', line 236 def validation_default false end |
Instance Method Details
#substitute(replacement) ⇒ Document?
Substitutes the supplied target documents for the existing document in the relation.
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/mongoid/relations/embedded/in.rb', line 51 def substitute(replacement) unbind_one unless replacement base.delete if persistable? return nil end base.new_record = true self.target = replacement bind_one self end |