Class: Dynamoid::Associations::BelongsTo
- Inherits:
-
Object
- Object
- Dynamoid::Associations::BelongsTo
- Includes:
- SingleAssociation
- Defined in:
- lib/dynamoid/associations/belongs_to.rb
Instance Attribute Summary
Attributes included from Association
#loaded, #name, #options, #source
Instance Method Summary collapse
-
#associate(hash_key) ⇒ Object
Override default implementation to handle case when we store id as scalar value, not as collection.
- #declaration_field_name ⇒ Object
- #declaration_field_type ⇒ Object
Methods included from SingleAssociation
#==, #create, #create!, #delete, #disassociate, #empty?, #method_missing, #nil?, #respond_to_missing?, #setter
Methods included from Association
#disassociate_source, #find_target, #initialize, #loaded?, #reset, #target
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Dynamoid::Associations::SingleAssociation
Instance Method Details
#associate(hash_key) ⇒ Object
Override default implementation to handle case when we store id as scalar value, not as collection
25 26 27 28 29 30 31 32 33 |
# File 'lib/dynamoid/associations/belongs_to.rb', line 25 def associate(hash_key) target.send(target_association).disassociate(source.hash_key) if target && target_association if [:foreign_key] source.update_attribute(source_attribute, hash_key) else source.update_attribute(source_attribute, Set[hash_key]) end end |
#declaration_field_name ⇒ Object
11 12 13 |
# File 'lib/dynamoid/associations/belongs_to.rb', line 11 def declaration_field_name [:foreign_key] || "#{name}_ids" end |
#declaration_field_type ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/dynamoid/associations/belongs_to.rb', line 15 def declaration_field_type if [:foreign_key] target_class.attributes[target_class.hash_key][:type] else :set end end |