Sha256: 7f8e4e52f676d5ebc1428fe838d8bb082c51001c4adf926398e5ee2551d7ef7e

Contents?: true

Size: 675 Bytes

Versions: 3

Compression:

Stored size: 675 Bytes

Contents

require 'rom/associations/abstract'

module ROM
  module Associations
    class OneToMany < Abstract
      # @api public
      def call(*)
        raise NotImplementedError
      end

      # @api public
      def foreign_key
        definition.foreign_key || target.foreign_key(source.name)
      end

      # @api private
      def associate(child, parent)
        pk, fk = join_key_map
        child.merge(fk => parent.fetch(pk))
      end

      protected

      # @api protected
      def source_key
        source.schema.primary_key_name
      end

      # @api protected
      def target_key
        foreign_key
      end

      memoize :foreign_key
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rom-core-4.0.0.beta3 lib/rom/associations/one_to_many.rb
rom-core-4.0.0.beta2 lib/rom/associations/one_to_many.rb
rom-core-4.0.0.beta1 lib/rom/associations/one_to_many.rb