Class: Mongoid::Association::Embedded::EmbedsOne
- Inherits:
-
Object
- Object
- Mongoid::Association::Embedded::EmbedsOne
- Defined in:
- lib/mongoid/association/embedded/embeds_one.rb,
lib/mongoid/association/embedded/embeds_one/proxy.rb,
lib/mongoid/association/embedded/embeds_one/binding.rb,
lib/mongoid/association/embedded/embeds_one/buildable.rb
Overview
The EmbedsOne 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.
[ :autobuild, :as, :cascade_callbacks, :cyclic, :store_as ]
- 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
#name, #options, #parent_inclusions
Instance Method Summary collapse
-
#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::One
The nested builder object.
-
#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 association object.
-
#stores_foreign_key? ⇒ false
Does this association type store the foreign key?.
-
#type ⇒ String | nil
The field used to store the type of the related object.
-
#validation_default ⇒ true | false
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, #in_to?, #initialize, #inverse, #inverse_association, #inverse_class, #inverse_class_name, #inverse_setter, #inverse_type, #inverse_type_setter, #inverses, #many?, #one?, #path, #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, #touchable?
Methods included from Constrainable
Instance Method Details
#embedded? ⇒ true
Is this association type embedded?
62 |
# File 'lib/mongoid/association/embedded/embeds_one.rb', line 62 def ; true; end |
#key ⇒ String
The key that is used to get the attributes for the associated object.
55 56 57 |
# File 'lib/mongoid/association/embedded/embeds_one.rb', line 55 def key store_as.to_s end |
#nested_builder(attributes, options) ⇒ Association::Nested::One
The nested builder object.
112 113 114 |
# File 'lib/mongoid/association/embedded/embeds_one.rb', line 112 def nested_builder(attributes, ) Nested::One.new(self, attributes, ) end |
#polymorphic? ⇒ true | false
Is this association polymorphic?
93 94 95 |
# File 'lib/mongoid/association/embedded/embeds_one.rb', line 93 def polymorphic? @polymorphic ||= !!@options[:as] end |
#primary_key ⇒ nil
The primary key
81 |
# File 'lib/mongoid/association/embedded/embeds_one.rb', line 81 def primary_key; end |
#relation ⇒ Association::Embedded::EmbedsMany::Proxy
Get the association proxy class for this association type.
86 87 88 |
# File 'lib/mongoid/association/embedded/embeds_one.rb', line 86 def relation Proxy end |
#setup! ⇒ self
Setup the instance methods, fields, etc. on the association owning class.
38 39 40 41 42 43 |
# File 'lib/mongoid/association/embedded/embeds_one.rb', line 38 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 association object.
48 49 50 |
# File 'lib/mongoid/association/embedded/embeds_one.rb', line 48 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?
76 |
# File 'lib/mongoid/association/embedded/embeds_one.rb', line 76 def stores_foreign_key?; false; end |
#type ⇒ String | nil
Only relevant if the association is polymorphic.
The field used to store the type of the related object.
102 103 104 |
# File 'lib/mongoid/association/embedded/embeds_one.rb', line 102 def type @type ||= "#{as}_type" if polymorphic? end |
#validation_default ⇒ true | false
Get the default validation setting for the association. Determines if by default a validates associated will occur.
71 |
# File 'lib/mongoid/association/embedded/embeds_one.rb', line 71 def validation_default; true; end |