Sha256: fe3edf058ba4fd1281edd3a47c170a4a53254cf38d0443b0d4d6a49d557a5b8b

Contents?: true

Size: 976 Bytes

Versions: 2

Compression:

Stored size: 976 Bytes

Contents

module Arel
  module Nodes
    class SubSelect < Node
      attr_accessor :select, :as

      def initialize(select, as = 'subquery')
        @select = select
        @as = as
      end
    end
  end

  module Visitors
    class ToSql
      def visit_Arel_Nodes_SubSelect o
        "(#{visit(o.select)}) AS #{o.as}"
      end
    end
  end

  class SelectManager
    def from table, as = nil
      table = case table
        when Arel::SelectManager
          Nodes::SubSelect.new(table.ast, as)
        when String
          Nodes::SqlLiteral.new(table)
        else
          table
        end

      # FIXME: this is a hack to support
      # test_with_two_tables_in_from_without_getting_double_quoted
      # from the AR tests.
      if @ctx.froms
        source = @ctx.froms

        if Nodes::SqlLiteral === table && Nodes::Join === source
          source.left = table
          table = source
        end
      end
      @ctx.froms = table
      self
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
composite_primary_keys-3.1.6 lib/composite_primary_keys/arel_extensions.rb
composite_primary_keys-3.1.5 lib/composite_primary_keys/arel_extensions.rb