Sha256: 87368daa26b1c5160d1f0c294afe60a073d7ec321a97230e64328e4d52273c0e
Contents?: true
Size: 1.65 KB
Versions: 3
Compression:
Stored size: 1.65 KB
Contents
require 'rom/types' require 'rom/associations/abstract' module ROM module Associations class ManyToMany < Abstract attr_reader :join_relation # @api private def initialize(*) super @join_relation = relations[through] end # @api public def call(*) raise NotImplementedError end # @api public def foreign_key definition.foreign_key || join_relation.foreign_key(source.name) end # @api public def through definition.through end # @api private def parent_combine_keys target.associations[source.name].combine_keys.to_a.flatten(1) end # @api private def associate(children, parent) ((spk, sfk), (tfk, tpk)) = join_key_map case parent when Array parent.map { |p| associate(children, p) }.flatten(1) else children.map { |tuple| { sfk => tuple.fetch(spk), tfk => parent.fetch(tpk) } } end end protected # @api protected def source_key source.primary_key end # @api protected def target_key foreign_key end # @api protected def join_assoc if join_relation.associations.key?(through.assoc_name) join_relation.associations[through.assoc_name] else join_relation.associations[through.target] end end # @api protected def join_key_map left = super right = join_assoc.join_key_map [left, right] end memoize :foreign_key, :join_assoc, :join_key_map end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rom-core-4.0.0.beta3 | lib/rom/associations/many_to_many.rb |
rom-core-4.0.0.beta2 | lib/rom/associations/many_to_many.rb |
rom-core-4.0.0.beta1 | lib/rom/associations/many_to_many.rb |