aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-08-10 00:06:30 +0100
committerJon Leighton <j@jonathanleighton.com>2011-08-15 23:10:15 +0100
commitfe0ec855419e1deba47277c96275a16ecf79bc9a (patch)
tree895f2bf111bc9e3e317d717804c48e5975dd326b /activerecord
parent43b99f290a8070196919a68999db87873257b7b8 (diff)
downloadrails-fe0ec855419e1deba47277c96275a16ecf79bc9a.tar.gz
rails-fe0ec855419e1deba47277c96275a16ecf79bc9a.tar.bz2
rails-fe0ec855419e1deba47277c96275a16ecf79bc9a.zip
Refactor building the update manager
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb8
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb5
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql_adapter.rb5
-rw-r--r--activerecord/lib/active_record/relation.rb11
4 files changed, 13 insertions, 16 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
index 83e64d3c43..d8bd33f72a 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
@@ -310,12 +310,10 @@ module ActiveRecord
# on mysql (even when aliasing the tables), but mysql allows using JOIN directly in
# an UPDATE statement, so in the mysql adapters we redefine this to do that.
def join_to_update(update, select) #:nodoc:
- subselect = select.clone
- subselect.ast.cores.last.projections = [update.ast.key]
+ subselect = select.ast.clone
+ subselect.cores.last.projections = [update.ast.key]
- update.ast.limit = nil
- update.ast.orders = []
- update.wheres = [update.ast.key.in(subselect)]
+ update.where update.ast.key.in(subselect)
end
protected
diff --git a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
index 172d08b6f4..41d410e062 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
@@ -594,11 +594,10 @@ module ActiveRecord
subselect = Arel::SelectManager.new(select.engine, subsubselect)
subselect.project(Arel::Table.new('__active_record_temp')[update.ast.key.name])
- update.ast.limit = nil
- update.ast.orders = []
- update.wheres = [update.ast.key.in(subselect)]
+ update.where update.ast.key.in(subselect)
else
update.table select.ast.cores.last.source
+ update.wheres = select.constraints
end
end
diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
index bd6cb2d3b8..d4aaf26bf3 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -508,11 +508,10 @@ module ActiveRecord
subselect = Arel::SelectManager.new(select.engine, subsubselect)
subselect.project(Arel::Table.new('__active_record_temp')[update.ast.key.name])
- update.ast.limit = nil
- update.ast.orders = []
- update.wheres = [update.ast.key.in(subselect)]
+ update.where update.ast.key.in(subselect)
else
update.table select.ast.cores.last.source
+ update.wheres = select.constraints
end
end
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index 565ece1930..15fd1a58c8 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -216,17 +216,18 @@ module ActiveRecord
if conditions || options.present?
where(conditions).apply_finder_options(options.slice(:limit, :order)).update_all(updates)
else
- stmt = arel.compile_update(Arel.sql(@klass.send(:sanitize_sql_for_assignment, updates)))
+ stmt = Arel::UpdateManager.new(arel.engine)
+
+ stmt.set Arel.sql(@klass.send(:sanitize_sql_for_assignment, updates))
+ stmt.table(table)
stmt.key = table[primary_key]
if joins_values.any?
@klass.connection.join_to_update(stmt, arel)
else
- if limit = arel.limit
- stmt.take limit
- end
-
+ stmt.take(arel.limit)
stmt.order(*arel.orders)
+ stmt.wheres = arel.constraints
end
@klass.connection.update stmt, 'SQL', bind_values