Sha256: 95d9bae5296f1b884390ce8a211f7c029c6a2956ca8b55f0bed5de06b613edd4

Contents?: true

Size: 746 Bytes

Versions: 10

Compression:

Stored size: 746 Bytes

Contents

# encoding: utf-8
module Dynamoid #:nodoc:

  # The HasMany association.
  module Associations
    class HasMany
      include Dynamoid::Associations::Association
      
      def ==(other)
        records == Array(other)
      end

      private

      def target_association
        key_name = source.class.to_s.singularize.downcase.to_sym
        guess = target_class.associations[key_name]
        return nil if guess.nil? || guess[:type] != :belongs_to
        key_name
      end
            
      def associate_target(object)
        object.update_attribute(target_attribute, Set[source.id])
      end
      
      def disassociate_target(object)
        object.update_attribute(target_attribute, nil)
      end
      
    end
  end
  
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
dynamoid-0.2.0 lib/dynamoid/associations/has_many.rb
dynamoid-0.1.2 lib/dynamoid/associations/has_many.rb
dynamoid-0.1.1 lib/dynamoid/associations/has_many.rb
dynamoid-0.1.0 lib/dynamoid/associations/has_many.rb
dynamoid-0.0.7 lib/dynamoid/associations/has_many.rb
dynamoid-0.0.6 lib/dynamoid/associations/has_many.rb
dynamoid-0.0.5 lib/dynamoid/associations/has_many.rb
dynamoid-0.0.4 lib/dynamoid/associations/has_many.rb
dynamoid-0.0.3 lib/dynamoid/associations/has_many.rb
dynamoid-0.0.2 lib/dynamoid/associations/has_many.rb