diff options
Diffstat (limited to 'lib/arel/relations')
-rw-r--r-- | lib/arel/relations/writes/update.rb | 11 |
1 files changed, 8 insertions, 3 deletions
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 |