class Dynamoid::Associations::BelongsTo
Private Instance Methods
associate_target(object)
click to toggle source
Associate a source object to this association.
@since 0.2.0
# File lib/dynamoid/associations/belongs_to.rb, line 31 def associate_target(object) object.update_attribute(target_attribute, target_ids.merge(Array(source.id))) end
disassociate_target(object)
click to toggle source
Disassociate a source object from this association.
@since 0.2.0
# File lib/dynamoid/associations/belongs_to.rb, line 38 def disassociate_target(object) source.update_attribute(source_attribute, target_ids - Array(source.id)) end
target_association()
click to toggle source
Find the target association, either has_many or has_one. Uses either options or the source class name and default parsing to return the most likely name for the target association.
@since 0.2.0
# File lib/dynamoid/associations/belongs_to.rb, line 16 def target_association has_many_key_name = options[:inverse_of] || source.class.to_s.underscore.pluralize.to_sym has_one_key_name = options[:inverse_of] || source.class.to_s.underscore.to_sym if !target_class.associations[has_many_key_name].nil? return has_many_key_name if target_class.associations[has_many_key_name][:type] == :has_many end if !target_class.associations[has_one_key_name].nil? return has_one_key_name if target_class.associations[has_one_key_name][:type] == :has_one end end