From d1ec33d69d85a3608aef9b064bc2c4799a214000 Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Tue, 4 Feb 2014 11:38:00 +0100 Subject: Allow assignment right member to reference columns Such queries become possible for mortals: ```ruby table.where(table[:qux].eq 'zomg').compile_update(table[:foo] => table[:bar]) ``` Arguably much more sane than using `engine.connection.quote_column_name` or `engine.connection.visitor.accept` on the right hand (bar), which is totally leaking the abstraction. --- lib/arel/visitors/to_sql.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lib/arel') diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index 554f98da14..ede43095ab 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 -- cgit v1.2.3