1
0
Fork 0
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:
Aaron Patterson 2010-09-10 13:36:42 -07:00
parent e060610897
commit 1ba8ac0848
4 changed files with 21 additions and 3 deletions

View file

@ -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'

View file

@ -0,0 +1,6 @@
module Arel
module Nodes
class Assignment < Arel::Nodes::Binary
end
end
end

View file

@ -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
) )

View file

@ -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