class Dynamoid::Associations::HasAndBelongsToMany

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/has_and_belongs_to_many.rb, line 25
def associate_target(object)
  ids = object.send(target_attribute) || Set.new
  object.update_attribute(target_attribute, 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/has_and_belongs_to_many.rb, line 33
def disassociate_target(object)
  ids = object.send(target_attribute) || Set.new
  object.update_attribute(target_attribute, ids - Array(source.id))
end
target_association() click to toggle source

Find the target association, always another :has_and_belongs_to_many association. 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/has_and_belongs_to_many.rb, line 15
def target_association
  key_name = options[:inverse_of] || source.class.to_s.pluralize.underscore.to_sym
  guess = target_class.associations[key_name]
  return nil if guess.nil? || guess[:type] != :has_and_belongs_to_many
  key_name
end