diff options
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 9 | ||||
-rw-r--r-- | test/visitors/test_to_sql.rb | 11 |
2 files changed, 18 insertions, 2 deletions
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index bd0cd8f03c..236f0354b1 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -501,8 +501,13 @@ module Arel end def visit_Arel_Nodes_Assignment o, a - right = quote(o.right, column_for(o.left)) - "#{visit o.left, a} = #{right}" + case o.right + when Arel::Nodes::UnqualifiedColumn, Arel::Attributes::Attribute + "#{visit o.left, a} = #{visit o.right, a}" + else + right = quote(o.right, column_for(o.left)) + "#{visit o.left, a} = #{right}" + end end def visit_Arel_Nodes_Equality o, a diff --git a/test/visitors/test_to_sql.rb b/test/visitors/test_to_sql.rb index 35effd4105..b4fdd51abd 100644 --- a/test/visitors/test_to_sql.rb +++ b/test/visitors/test_to_sql.rb @@ -208,6 +208,17 @@ module Arel } end + it "should visit_Arel_Nodes_Assignment" do + column = @table["id"] + node = Nodes::Assignment.new( + Nodes::UnqualifiedColumn.new(column), + Nodes::UnqualifiedColumn.new(column) + ) + @visitor.accept(node).must_be_like %{ + "id" = "id" + } + end + it "should visit visit_Arel_Attributes_Time" do attr = Attributes::Time.new(@attr.relation, @attr.name) @visitor.accept attr |