mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
differentiating equality and assignment
This commit is contained in:
parent
e060610897
commit
1ba8ac0848
4 changed files with 21 additions and 3 deletions
|
@ -1,5 +1,6 @@
|
||||||
require 'arel/nodes/binary'
|
require 'arel/nodes/binary'
|
||||||
require 'arel/nodes/equality'
|
require 'arel/nodes/equality'
|
||||||
|
require 'arel/nodes/assignment'
|
||||||
require 'arel/nodes/or'
|
require 'arel/nodes/or'
|
||||||
require 'arel/nodes/and'
|
require 'arel/nodes/and'
|
||||||
require 'arel/nodes/greater_than'
|
require 'arel/nodes/greater_than'
|
||||||
|
|
6
lib/arel/nodes/assignment.rb
Normal file
6
lib/arel/nodes/assignment.rb
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
module Arel
|
||||||
|
module Nodes
|
||||||
|
class Assignment < Arel::Nodes::Binary
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -26,7 +26,7 @@ module Arel
|
||||||
@head.values = [values]
|
@head.values = [values]
|
||||||
else
|
else
|
||||||
@head.values = values.map { |column,value|
|
@head.values = values.map { |column,value|
|
||||||
Nodes::Equality.new(
|
Nodes::Assignment.new(
|
||||||
Nodes::UnqualifiedColumn.new(column),
|
Nodes::UnqualifiedColumn.new(column),
|
||||||
value
|
value
|
||||||
)
|
)
|
||||||
|
|
|
@ -149,13 +149,24 @@ module Arel
|
||||||
"#{visit o.left} OR #{visit o.right}"
|
"#{visit o.left} OR #{visit o.right}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def visit_Arel_Nodes_Equality o
|
def visit_Arel_Nodes_Assignment o
|
||||||
right = o.right
|
right = o.right
|
||||||
# FIXME: maybe we should visit NilClass?
|
|
||||||
right = right.nil? ? 'NULL' : visit(right)
|
right = right.nil? ? 'NULL' : visit(right)
|
||||||
"#{visit o.left} = #{right}"
|
"#{visit o.left} = #{right}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def visit_Arel_Nodes_Equality o
|
||||||
|
right = o.right
|
||||||
|
|
||||||
|
# FIXME: maybe we should visit NilClass?
|
||||||
|
if right.nil?
|
||||||
|
"#{visit o.left} IS NULL"
|
||||||
|
else
|
||||||
|
"#{visit o.left} = #{visit right}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def visit_Arel_Nodes_UnqualifiedColumn o
|
def visit_Arel_Nodes_UnqualifiedColumn o
|
||||||
"#{quote_column_name o.name}"
|
"#{quote_column_name o.name}"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue