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?, #setter
Methods included from Association
#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
24 25 26 27 28 29 30 31 32 |
# File 'lib/dynamoid/associations/belongs_to.rb', line 24 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
10 11 12 |
# File 'lib/dynamoid/associations/belongs_to.rb', line 10 def declaration_field_name [:foreign_key] || "#{name}_ids" end |
#declaration_field_type ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/dynamoid/associations/belongs_to.rb', line 14 def declaration_field_type if [:foreign_key] target_class.attributes[target_class.hash_key][:type] else :set end end |