aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/visitors/to_sql.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-09-23 15:26:08 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-09-23 15:26:08 -0700
commit80ad95bae41f4f5923faeb2e7b9cab4287e54fe9 (patch)
tree606c0335a71eb4f7a3223da3aad8a37a32cb761d /lib/arel/visitors/to_sql.rb
parent445a0ea342c28b8a6598343db40ad776cffd3a2e (diff)
downloadrails-80ad95bae41f4f5923faeb2e7b9cab4287e54fe9.tar.gz
rails-80ad95bae41f4f5923faeb2e7b9cab4287e54fe9.tar.bz2
rails-80ad95bae41f4f5923faeb2e7b9cab4287e54fe9.zip
moving visitors around
Diffstat (limited to 'lib/arel/visitors/to_sql.rb')
-rw-r--r--lib/arel/visitors/to_sql.rb18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb
index 2ccc9d7d3f..d1cb115238 100644
--- a/lib/arel/visitors/to_sql.rb
+++ b/lib/arel/visitors/to_sql.rb
@@ -22,15 +22,25 @@ module Arel
end
def visit_Arel_Nodes_UpdateStatement o
+ if o.orders.empty? && o.limit.nil?
+ wheres = o.wheres
+ else
+ stmt = Nodes::SelectStatement.new
+ core = stmt.cores.first
+ core.froms = o.relation
+ core.projections = [o.relation.primary_key]
+ stmt.limit = o.limit
+ stmt.orders = o.orders
+
+ wheres = [Nodes::In.new(o.relation.primary_key, [stmt])]
+ end
+
[
"UPDATE #{visit o.relation}",
("SET #{o.values.map { |value| visit value }.join ', '}" unless o.values.empty?),
- ("WHERE #{o.wheres.map { |x| visit x }.join ' AND '}" unless o.wheres.empty?),
- ("ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?),
- ("LIMIT #{o.limit}" if o.limit),
+ ("WHERE #{wheres.map { |x| visit x }.join ' AND '}" unless wheres.empty?)
].compact.join ' '
end
-
def visit_Arel_Nodes_InsertStatement o
[
"INSERT INTO #{visit o.relation}",