Class: Mongoid::Association::Referenced::BelongsTo
- Inherits:
-
Object
- Object
- Mongoid::Association::Referenced::BelongsTo
- Includes:
- Buildable, Mongoid::Association::Relatable
- Defined in:
- build/mongoid-7.3/lib/mongoid/association/referenced/belongs_to.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/belongs_to/binding.rb,
build/mongoid-7.3/lib/mongoid/association/referenced/belongs_to/buildable.rb
Overview
The BelongsTo type 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.
[ :autobuild, :autosave, :counter_cache, :dependent, :foreign_key, :index, :polymorphic, :primary_key, :touch, :optional, :required ].freeze
- VALID_OPTIONS =
The complete list of valid options for this association, including the shared ones.
(ASSOCIATION_OPTIONS + SHARED_OPTIONS).freeze
- FOREIGN_KEY_FIELD_TYPE =
The type of the field holding the foreign key.
Object
- FOREIGN_KEY_SUFFIX =
The default foreign key suffix.
'_id'.freeze
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
Instance Method Summary collapse
-
#embedded? ⇒ false
Is this association type embedded?.
-
#foreign_key ⇒ String
Get the foreign key field for saving the association reference.
-
#inverse_type ⇒ String
The name of the field used to store the type of polymorphic association.
-
#nested_builder(attributes, options) ⇒ Association::Nested::One
The nested builder object.
-
#path(document) ⇒ Root
Get the path calculator for the supplied document.
-
#polymorphic? ⇒ true, false
Is this association polymorphic?.
-
#relation ⇒ Association::BelongsTo::Proxy
Get the association proxy class for this association type.
-
#relation_complements ⇒ Array<Association>
The list of association complements.
-
#setup! ⇒ self
Setup the instance methods, fields, etc.
-
#stores_foreign_key? ⇒ true
Does this association type store the foreign key?.
-
#validation_default ⇒ false
The default for validation the association object.
Methods included from Buildable
Methods included from Mongoid::Association::Relatable
#==, #bindable?, #counter_cache_column_name, #create_relation, #destructive?, #extension, #foreign_key_check, #foreign_key_setter, #get_callbacks, #initialize, #inverse, #inverse_association, #inverse_class, #inverse_class_name, #inverse_setter, #inverse_type_setter, #inverses, #key, #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, #primary_key, #store_as, #touch_field, #type
Methods included from Constrainable
Instance Method Details
#embedded? ⇒ false
Is this association type embedded?
94 |
# File 'build/mongoid-7.3/lib/mongoid/association/referenced/belongs_to.rb', line 94 def ; false; end |
#foreign_key ⇒ String
Get the foreign key field for saving the association reference.
108 109 110 111 |
# File 'build/mongoid-7.3/lib/mongoid/association/referenced/belongs_to.rb', line 108 def foreign_key @foreign_key ||= @options[:foreign_key] ? @options[:foreign_key].to_s : default_foreign_key_field end |
#inverse_type ⇒ String
The name of the field used to store the type of polymorphic association.
136 137 138 |
# File 'build/mongoid-7.3/lib/mongoid/association/referenced/belongs_to.rb', line 136 def inverse_type (@inverse_type ||= "#{name}_type") if polymorphic? end |
#nested_builder(attributes, options) ⇒ Association::Nested::One
The nested builder object.
148 149 150 |
# File 'build/mongoid-7.3/lib/mongoid/association/referenced/belongs_to.rb', line 148 def nested_builder(attributes, ) Nested::One.new(self, attributes, ) end |
#path(document) ⇒ Root
Get the path calculator for the supplied document.
162 163 164 |
# File 'build/mongoid-7.3/lib/mongoid/association/referenced/belongs_to.rb', line 162 def path(document) Mongoid::Atomic::Paths::Root.new(document) end |
#polymorphic? ⇒ true, false
Is this association polymorphic?
127 128 129 |
# File 'build/mongoid-7.3/lib/mongoid/association/referenced/belongs_to.rb', line 127 def polymorphic? @polymorphic ||= !!@options[:polymorphic] end |
#relation ⇒ Association::BelongsTo::Proxy
Get the association proxy class for this association type.
118 119 120 |
# File 'build/mongoid-7.3/lib/mongoid/association/referenced/belongs_to.rb', line 118 def relation Proxy end |
#relation_complements ⇒ Array<Association>
The list of association complements.
67 68 69 |
# File 'build/mongoid-7.3/lib/mongoid/association/referenced/belongs_to.rb', line 67 def relation_complements @relation_complements ||= [ HasMany, HasOne ].freeze end |
#setup! ⇒ self
Setup the instance methods, fields, etc. on the association owning class.
76 77 78 79 80 |
# File 'build/mongoid-7.3/lib/mongoid/association/referenced/belongs_to.rb', line 76 def setup! setup_instance_methods! @owner_class.aliased_fields[name.to_s] = foreign_key self end |
#stores_foreign_key? ⇒ true
Does this association type store the foreign key?
87 |
# File 'build/mongoid-7.3/lib/mongoid/association/referenced/belongs_to.rb', line 87 def stores_foreign_key?; true; end |
#validation_default ⇒ false
The default for validation the association object.
101 |
# File 'build/mongoid-7.3/lib/mongoid/association/referenced/belongs_to.rb', line 101 def validation_default; false; end |