diff options
Diffstat (limited to 'lib/arel/crud.rb')
-rw-r--r-- | lib/arel/crud.rb | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/arel/crud.rb b/lib/arel/crud.rb index b1269bd1da..196dc56554 100644 --- a/lib/arel/crud.rb +++ b/lib/arel/crud.rb @@ -7,12 +7,23 @@ module Arel um = UpdateManager.new @engine if Nodes::SqlLiteral === values - um.table @ctx.froms.last + relation = @ctx.froms.last else - um.table values.first.first.relation + relation = values.first.first.relation end + um.table relation um.set values - um.wheres = @ctx.wheres + + if @head.orders.empty? && @head.limit.nil? + um.wheres = @ctx.wheres + else + head = @head.clone + core = head.cores.first + core.projections = [relation.primary_key] + + um.wheres = [Nodes::In.new(relation.primary_key, [head])] + end + @engine.connection.update um.to_sql, 'AREL' end |