diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/arel/nodes/update_statement.rb | 3 | ||||
-rw-r--r-- | lib/arel/update_manager.rb | 5 | ||||
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 3 |
3 files changed, 10 insertions, 1 deletions
diff --git a/lib/arel/nodes/update_statement.rb b/lib/arel/nodes/update_statement.rb index 66996f11a3..3df54bb3a9 100644 --- a/lib/arel/nodes/update_statement.rb +++ b/lib/arel/nodes/update_statement.rb @@ -1,11 +1,12 @@ module Arel module Nodes class UpdateStatement - attr_accessor :relation, :wheres + attr_accessor :relation, :wheres, :values def initialize @relation = nil @wheres = [] + @values = nil end end end diff --git a/lib/arel/update_manager.rb b/lib/arel/update_manager.rb index 3af73d2962..cc2f973842 100644 --- a/lib/arel/update_manager.rb +++ b/lib/arel/update_manager.rb @@ -16,5 +16,10 @@ module Arel @head.wheres << expr self end + + def set values + @head.values = values + self + end end end diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index 41d1299948..9a9dd20d52 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -15,6 +15,9 @@ module Arel def visit_Arel_Nodes_UpdateStatement o [ "UPDATE #{visit o.relation}", + ("SET #{o.values.map { |column,value| + "#{quote_column_name(column.name)} = #{quote visit value}" + }.join ', '}" if o.values), ("WHERE #{o.wheres.map { |x| visit x }.join ' AND '}" unless o.wheres.empty?) ].compact.join ' ' end |