Class: ParamsReady::Query::JoinCondition

Inherits:
Object
  • Object
show all
Defined in:
lib/params_ready/query/join_clause.rb

Defined Under Namespace

Classes: Builder

Instance Method Summary collapse

Constructor Details

#initialize(on, op, to) ⇒ JoinCondition

Returns a new instance of JoinCondition.



129
130
131
132
133
134
# File 'lib/params_ready/query/join_clause.rb', line 129

def initialize(on, op, to)
  @on = on
  @op = op
  @to = to
  freeze
end

Instance Method Details

#to_arel(base_table, join_table, context, parameter) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/params_ready/query/join_clause.rb', line 136

def to_arel(base_table, join_table, context, parameter)
  if @to.nil?
    grouping =  @on.to_arel(:none, context, parameter)
    return grouping if grouping.is_a? Arel::Nodes::Node

    Arel::Nodes::Grouping.new(grouping)
  else
    lhs =  @on.to_arel(base_table, context, parameter)
    rhs = @to.to_arel(join_table, context, parameter)
    lhs.send(@op, rhs)
  end
end