aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/relations/utilities/externalization.rb
blob: 3b9b2296dc2c28826f15dc47d02db3b7da3d8fb8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module Arel
  class Externalization < Compound
    attributes :relation
    deriving :initialize, :==
    include Recursion::BaseCase

    def wheres
      []
    end

    def table_sql(formatter = Sql::TableReference.new(relation))
      formatter.select relation.select_sql, self
    end

    def attributes
      @attributes ||= relation.attributes.collect(&:to_attribute).collect { |a| a.bind(self) }
    end

    # REMOVEME
    def name
      relation.name + '_external'
    end
  end

  class Relation
    def externalize
      @externalized ||= externalizable?? Externalization.new(self) : self
    end

    def externalizable?
      false
    end
  end
end