Class: Mongoid::Relations::Embedded::One
- Defined in:
- lib/mongoid/relations/embedded/one.rb
Overview
This class defines the behaviour needed for embedded one to one relations.
Instance Attribute Summary
Attributes inherited from Proxy
#base, #loaded, #metadata, #target
Class Method Summary collapse
-
.builder(meta, object, loading = false) ⇒ 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.
-
.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) ⇒ Mongoid::Atomic::Paths::Embedded::One
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) ⇒ One
constructor
Instantiate a new embeds_one relation.
-
#substitute(replacement) ⇒ Document?
Substitutes the supplied target documents for the existing document in the relation.
Methods inherited from One
Methods inherited from Proxy
Constructor Details
#initialize(base, target, metadata) ⇒ One
Instantiate a new embeds_one relation.
18 19 20 21 22 23 24 |
# File 'lib/mongoid/relations/embedded/one.rb', line 18 def initialize(base, target, ) init(base, target, ) do characterize_one(target) bind_one target.save if persistable? 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(meta, object, loading = false) ⇒ Builder
Return the builder that is responsible for generating the documents that will be used by this relation.
93 94 95 |
# File 'lib/mongoid/relations/embedded/one.rb', line 93 def builder(, object, loading = false) Builders::Embedded::One.new(, object, loading) end |
.embedded? ⇒ true
Returns true if the relation is an embedded one. In this case always true.
106 107 108 |
# File 'lib/mongoid/relations/embedded/one.rb', line 106 def true end |
.macro ⇒ Symbol
Returns the macro for this relation. Used mostly as a helper in reflection.
119 120 121 |
# File 'lib/mongoid/relations/embedded/one.rb', line 119 def macro :embeds_one 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.
145 146 147 |
# File 'lib/mongoid/relations/embedded/one.rb', line 145 def nested_builder(, attributes, ) Builders::NestedAttributes::One.new(, attributes, ) end |
.path(document) ⇒ Mongoid::Atomic::Paths::Embedded::One
Get the path calculator for the supplied document.
160 161 162 |
# File 'lib/mongoid/relations/embedded/one.rb', line 160 def path(document) Mongoid::Atomic::Paths::Embedded::One.new(document) end |
.stores_foreign_key? ⇒ false
Tells the caller if this relation is one that stores the foreign key on its own objects.
173 174 175 |
# File 'lib/mongoid/relations/embedded/one.rb', line 173 def stores_foreign_key? false end |
.valid_options ⇒ Array<Symbol>
Get the valid options allowed with this relation.
185 186 187 |
# File 'lib/mongoid/relations/embedded/one.rb', line 185 def [ :as, :cyclic ] end |
.validation_default ⇒ true, false
Get the default validation setting for the relation. Determines if by default a validates associated will occur.
198 199 200 |
# File 'lib/mongoid/relations/embedded/one.rb', line 198 def validation_default true end |
Instance Method Details
#substitute(replacement) ⇒ Document?
Substitutes the supplied target documents for the existing document in the relation.
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/mongoid/relations/embedded/one.rb', line 37 def substitute(replacement) tap do |proxy| if assigning? base.atomic_unsets.push(proxy.atomic_path) else proxy.delete if persistable? end proxy.unbind_one return nil unless replacement proxy.target = replacement proxy.bind_one end end |