Sha256: 0fdb721c88de8b907508010fb9e79c96ae397e95530277ec035782cc9afe7e2e

Contents?: true

Size: 762 Bytes

Versions: 6

Compression:

Stored size: 762 Bytes

Contents

# frozen_string_literal: true

module Dynamoid
  # The has and belongs to many association.
  module Associations
    # @private
    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

6 entries across 6 versions & 1 rubygems

Version Path
dynamoid-3.10.0 lib/dynamoid/associations/has_and_belongs_to_many.rb
dynamoid-3.9.0 lib/dynamoid/associations/has_and_belongs_to_many.rb
dynamoid-3.8.0 lib/dynamoid/associations/has_and_belongs_to_many.rb
dynamoid-3.7.1 lib/dynamoid/associations/has_and_belongs_to_many.rb
dynamoid-3.7.0 lib/dynamoid/associations/has_and_belongs_to_many.rb
dynamoid-3.6.0 lib/dynamoid/associations/has_and_belongs_to_many.rb