aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/visitors/join_sql.rb
blob: 427f2bb72642636d5d4f6582076522c711dc5c0d (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
35
36
37
38
39
40
41
module Arel
  module Visitors
    ###
    # This class produces SQL for JOIN clauses but omits the "single-source"
    # part of the Join grammar:
    #
    #   http://www.sqlite.org/syntaxdiagrams.html#join-source
    #
    # This visitor is used in SelectManager#join_sql and is for backwards
    # compatibility with Arel V1.0
    module JoinSql
      private

      def visit_Arel_Nodes_SelectCore o
        return '' unless Nodes::Join === o.from
        visit o.from
      end

      def visit_Arel_Nodes_StringJoin o
        [
          (visit o.left if Nodes::Join === o.left),
          visit(o.right)
        ].compact.join ' '
      end

      def visit_Arel_Nodes_OuterJoin o
        [
          (visit o.left if Nodes::Join === o.left),
          "LEFT OUTER JOIN #{visit o.right} #{visit o.constraint if o.constraint}"
        ].compact.join ' '
      end

      def visit_Arel_Nodes_InnerJoin o
        [
          (visit o.left if Nodes::Join === o.left),
          "INNER JOIN #{visit o.right} #{visit o.constraint if o.constraint}"
        ].compact.join ' '
      end
    end
  end
end