Sha256: c803b1cd8220a4e0937b4d6bb49cb4418861c668441b0a51644a77d2236bbbdd

Contents?: true

Size: 744 Bytes

Versions: 3

Compression:

Stored size: 744 Bytes

Contents

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

  # The has and belongs to many association.
  module Associations
    class HasAndBelongsToMany
      include ManyAssociation

      private

      # Find the target association, always another :has_and_belongs_to_many association. Uses either options[:inverse_of] or the source class name
      # and default parsing to return the most likely name for the target association.
      #
      # @since 0.2.0
      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
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dynamoid-2.2.0 lib/dynamoid/associations/has_and_belongs_to_many.rb
dynamoid-2.1.0 lib/dynamoid/associations/has_and_belongs_to_many.rb
dynamoid-2.0.0 lib/dynamoid/associations/has_and_belongs_to_many.rb