diff options
author | Emilio Tagua <miloops@gmail.com> | 2009-05-18 20:00:38 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2009-05-18 20:00:38 -0300 |
commit | 4b8526dddd6a906a1879ec786401070b3545d7f4 (patch) | |
tree | e3b604a1abfccbfeb76a7df071d9cbc21e58189c /lib/arel/relations | |
parent | b522778a61670825948e2fbd4a3353583c1c7223 (diff) | |
download | rails-4b8526dddd6a906a1879ec786401070b3545d7f4.tar.gz rails-4b8526dddd6a906a1879ec786401070b3545d7f4.tar.bz2 rails-4b8526dddd6a906a1879ec786401070b3545d7f4.zip |
Don't quote columns when they are not an attribute
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 |