Sha256: a49046f232851e8e7b7d16a9396867bf7572ecdbe4d30cb8b813745d6e2df9b2

Contents?: true

Size: 990 Bytes

Versions: 6

Compression:

Stored size: 990 Bytes

Contents

require 'rom/relation/wrap'

module ROM
  module SQL
    # Specialized wrap relation for SQL
    #
    # This type of relations is returned when using `Relation#wrap` and it uses
    # a join, unlike `Relation#combine`, which means a relation is restricted
    # only to tuples which have associated tuples. It should be used in cases
    # where you want to rely on this restriction.
    #
    # @api public
    class Wrap < Relation::Wrap
      # Return a schema which includes attributes from wrapped relations
      #
      # @return [Schema]
      #
      # @api public
      def schema
        root.schema.merge(nodes.map(&:schema).reduce(:merge)).qualified
      end

      # Internal method used by abstract `ROM::Relation::Wrap`
      #
      # @return [Relation]
      #
      # @api private
      def relation
        relation = nodes.reduce(root) do |a, e|
          a.associations[e.name.key].join(:join, a, e)
        end
        schema.(relation)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rom-sql-2.3.0 lib/rom/sql/wrap.rb
rom-sql-2.2.1 lib/rom/sql/wrap.rb
rom-sql-2.2.0 lib/rom/sql/wrap.rb
rom-sql-2.1.0 lib/rom/sql/wrap.rb
rom-sql-2.0.0 lib/rom/sql/wrap.rb
rom-sql-2.0.0.rc1 lib/rom/sql/wrap.rb