Class: Squeel::Nodes::As

Inherits:
Binary show all
Defined in:
lib/squeel/nodes/as.rb

Overview

A node representing an SQL alias, which will result in same when visited.

Instance Attribute Summary

Attributes inherited from Binary

#left, #right

Instance Method Summary collapse

Methods inherited from Binary

#eql?, #hash

Methods included from PredicateOperators

#&, #-@, #|

Methods inherited from Node

#each, #grep

Constructor Details

#initialize(left, right) ⇒ As

Returns a new instance of As.

Parameters:

  • left

    The node to be aliased

  • right

    The alias name



12
13
14
# File 'lib/squeel/nodes/as.rb', line 12

def initialize(left, right)
  @left, @right = left, right
end

Instance Method Details

#on(*args) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/squeel/nodes/as.rb', line 16

def on(*args)
  raise "only can convert ActiveRecord::Relation to a join node" unless left.is_a?(ActiveRecord::Relation)
  proc =
    if block_given?
      DSL.eval(&Proc.new)
    else
      args
    end

  SubqueryJoin.new(self, proc)
end