Class: Mongoid::Association::Referenced::HasOne
- Inherits:
-
Object
- Object
- Mongoid::Association::Referenced::HasOne
- Includes:
- Buildable, Mongoid::Association::Relatable
- Defined in:
- lib/mongoid/association/referenced/has_one.rb,
lib/mongoid/association/referenced/has_one/eager.rb,
lib/mongoid/association/referenced/has_one/proxy.rb,
lib/mongoid/association/referenced/has_one/binding.rb,
lib/mongoid/association/referenced/has_one/buildable.rb
Overview
The has_one association.
Defined Under Namespace
Modules: Buildable Classes: Binding, Eager, Proxy
Constant Summary collapse
- ASSOCIATION_OPTIONS =
The options available for this type of association, in addition to the common ones.
i[ as autobuild autosave dependent fallback foreign_key primary_key scope ].freeze
- VALID_OPTIONS =
The complete list of valid options for this association, including the shared ones.
(ASSOCIATION_OPTIONS + SHARED_OPTIONS).freeze
- FOREIGN_KEY_SUFFIX =
The default foreign key suffix.
'_id'
Constants included from Mongoid::Association::Relatable
Mongoid::Association::Relatable::PRIMARY_KEY_DEFAULT, Mongoid::Association::Relatable::SHARED_OPTIONS
Instance Attribute Summary
Attributes included from Mongoid::Association::Relatable
#name, #options, #owner_class, #parent_inclusions
Instance Method Summary collapse
-
#bindable?(doc) ⇒ true | false
Whether trying to bind an object using this association should raise an error.
-
#embedded? ⇒ false
Is this association type embedded?.
-
#foreign_key ⇒ String
Get the foreign key field for saving the association reference.
-
#nested_builder(attributes, options) ⇒ Association::Nested::Many
The nested builder object.
-
#path(document) ⇒ Root
Get the path calculator for the supplied document.
-
#polymorphic? ⇒ true | false
Is this association polymorphic?.
-
#relation ⇒ Association::HasOne::Proxy
Get the association proxy class for this association type.
-
#relation_complements ⇒ Array<Mongoid::Association::Relatable>
The list of association complements.
-
#scope ⇒ Proc | Symbol | nil
Get the scope to be applied when querying the association.
-
#setup! ⇒ self
Setup the instance methods, fields, etc.
-
#stores_foreign_key? ⇒ false
Does this association type store the foreign key?.
-
#type ⇒ String | nil
The type of this association if it's polymorphic.
-
#validation_default ⇒ true
The default for validation the association object.
Methods included from Buildable
Methods included from WithPolymorphicCriteria
Methods included from Mongoid::Association::Relatable
#==, #counter_cache_column_name, #create_relation, #destructive?, #extension, #foreign_key_check, #foreign_key_setter, #get_callbacks, #in_to?, #initialize, #inverse, #inverse_association, #inverse_class, #inverse_class_name, #inverse_setter, #inverse_type, #inverse_type_setter, #inverses, #key, #many?, #many_to_many?, #one?, #relation_class, #relation_class_name, #setter, #try_relation_class, #type_setter, #validate?
Methods included from Options
#as, #autobuilding?, #autosave, #cascading_callbacks?, #counter_cached?, #cyclic?, #dependent, #fallback, #fallback?, #forced_nil_inverse?, #indexed?, #inverse_of, #order, #primary_key, #store_as, #touch_field, #touchable?
Methods included from Constrainable
Instance Method Details
#bindable?(doc) ⇒ true | false
Whether trying to bind an object using this association should raise an error.
122 123 124 |
# File 'lib/mongoid/association/referenced/has_one.rb', line 122 def bindable?(doc) forced_nil_inverse? || (!!inverse && doc.fields.keys.include?(foreign_key)) end |
#embedded? ⇒ false
Is this association type embedded?
72 73 74 |
# File 'lib/mongoid/association/referenced/has_one.rb', line 72 def false end |
#foreign_key ⇒ String
Get the foreign key field for saving the association reference.
61 62 63 64 65 66 67 |
# File 'lib/mongoid/association/referenced/has_one.rb', line 61 def foreign_key @foreign_key ||= if [:foreign_key] [:foreign_key].to_s else default_foreign_key_field end end |
#nested_builder(attributes, options) ⇒ Association::Nested::Many
The nested builder object.
96 97 98 |
# File 'lib/mongoid/association/referenced/has_one.rb', line 96 def nested_builder(attributes, ) Nested::One.new(self, attributes, ) end |
#path(document) ⇒ Root
Get the path calculator for the supplied document.
141 142 143 |
# File 'lib/mongoid/association/referenced/has_one.rb', line 141 def path(document) Mongoid::Atomic::Paths::Root.new(document) end |
#polymorphic? ⇒ true | false
Is this association polymorphic?
103 104 105 |
# File 'lib/mongoid/association/referenced/has_one.rb', line 103 def polymorphic? @polymorphic ||= !!as end |
#relation ⇒ Association::HasOne::Proxy
Get the association proxy class for this association type.
86 87 88 |
# File 'lib/mongoid/association/referenced/has_one.rb', line 86 def relation Proxy end |
#relation_complements ⇒ Array<Mongoid::Association::Relatable>
The list of association complements.
45 46 47 |
# File 'lib/mongoid/association/referenced/has_one.rb', line 45 def relation_complements @relation_complements ||= [ Referenced::BelongsTo ].freeze end |
#scope ⇒ Proc | Symbol | nil
Get the scope to be applied when querying the association.
148 149 150 |
# File 'lib/mongoid/association/referenced/has_one.rb', line 148 def scope [:scope] end |
#setup! ⇒ self
Setup the instance methods, fields, etc. on the association owning class.
52 53 54 55 |
# File 'lib/mongoid/association/referenced/has_one.rb', line 52 def setup! setup_instance_methods! self end |
#stores_foreign_key? ⇒ false
Does this association type store the foreign key?
129 130 131 |
# File 'lib/mongoid/association/referenced/has_one.rb', line 129 def stores_foreign_key? false end |
#type ⇒ String | nil
Only relevant for polymorphic associations.
The type of this association if it's polymorphic.
112 113 114 |
# File 'lib/mongoid/association/referenced/has_one.rb', line 112 def type @type ||= "#{as}_type" if polymorphic? end |
#validation_default ⇒ true
The default for validation the association object.
79 80 81 |
# File 'lib/mongoid/association/referenced/has_one.rb', line 79 def validation_default true end |