diff options
author | Loic Nageleisen <loic.nageleisen@gmail.com> | 2014-02-04 11:38:00 +0100 |
---|---|---|
committer | cmohanprasath <cmohanprasath@gmail.com> | 2014-02-11 19:09:53 +0200 |
commit | d1ec33d69d85a3608aef9b064bc2c4799a214000 (patch) | |
tree | 82dfb0cc30238bbfcfdb259788326ce51a252fca | |
parent | 048d6c0aefec9f233a77e9160f426cf2fed1b7f6 (diff) | |
download | rails-d1ec33d69d85a3608aef9b064bc2c4799a214000.tar.gz rails-d1ec33d69d85a3608aef9b064bc2c4799a214000.tar.bz2 rails-d1ec33d69d85a3608aef9b064bc2c4799a214000.zip |
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.
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 9 |
1 files changed, 7 insertions, 2 deletions
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 |