From 4b8526dddd6a906a1879ec786401070b3545d7f4 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Mon, 18 May 2009 20:00:38 -0300 Subject: Don't quote columns when they are not an attribute --- lib/arel/relations/writes/update.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/arel/relations/writes/update.rb b/lib/arel/relations/writes/update.rb index 2e90de3a52..52ca6ecf05 100644 --- a/lib/arel/relations/writes/update.rb +++ b/lib/arel/relations/writes/update.rb @@ -10,9 +10,7 @@ module Arel def to_sql(formatter = nil) [ "UPDATE #{table_sql} SET", - assignments.collect do |attribute, value| - "#{engine.quote_column_name(attribute.name)} = #{attribute.format(value)}" - end.join(",\n"), + map_assignments, ("WHERE #{wheres.map(&:to_sql).join('\n\tAND ')}" unless wheres.blank? ), ("LIMIT #{taken}" unless taken.blank? ) ].join("\n") @@ -21,5 +19,12 @@ module Arel def call(connection = engine) connection.update(to_sql) end + + def map_assignments + assignments.collect do |attribute, value| + attribute.respond_to?(:name) ? + "#{engine.quote_column_name(attribute.name)} = #{attribute.format(value)}" : attribute + end.join(",\n") + end end end -- cgit v1.2.3