Sha256: d7aa2a5854d91933e6d4f09ed9a4328c9cb64cbcf83c313dcd281bbf7b8c7d47
Contents?: true
Size: 914 Bytes
Versions: 9
Compression:
Stored size: 914 Bytes
Contents
# encoding: utf-8 module Dynamoid #:nodoc: # The habtm association. module Associations class HasAndBelongsToMany include Dynamoid::Associations::Association def ==(other) records == Array(other) end private def target_association key_name = source.class.to_s.pluralize.downcase.to_sym guess = target_class.associations[key_name] return nil if guess.nil? || guess[:type] != :has_and_belongs_to_many key_name end def associate_target(object) ids = object.send(target_attribute) || Set.new object.update_attribute(target_attribute, ids.merge(Array(source.id))) end def disassociate_target(object) ids = object.send(target_attribute) || Set.new object.update_attribute(target_attribute, ids - Array(source.id)) end end end end
Version data entries
9 entries across 9 versions & 1 rubygems