提交 5082cce6 编写于 作者: R Rafael Mendonça França

Revert "Merge pull request #22615 from kamipo/join_to_delete_is_same_as_join_to_update"

This reverts commit 4d06ea9a, reversing
changes made to e9d15072.

Reason: This will break oracle-enhanced, see
https://github.com/rsim/oracle-enhanced/blob/3c42131db82b64ac41645db3affc6e4650289df6/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb#L1254
上级 4d06ea9a
...@@ -344,12 +344,18 @@ def sanitize_limit(limit) ...@@ -344,12 +344,18 @@ def sanitize_limit(limit)
# The default strategy for an UPDATE with joins is to use a subquery. This doesn't work # The default strategy for an UPDATE with joins is to use a subquery. This doesn't work
# on MySQL (even when aliasing the tables), but MySQL allows using JOIN directly in # 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. # an UPDATE statement, so in the MySQL adapters we redefine this to do that.
def join_to_update(update, select, key) # :nodoc: def join_to_update(update, select) #:nodoc:
key = update.key
subselect = subquery_for(key, select) subselect = subquery_for(key, select)
update.where key.in(subselect) update.where key.in(subselect)
end end
alias join_to_delete join_to_update
def join_to_delete(delete, select, key) #:nodoc:
subselect = subquery_for(key, select)
delete.where key.in(subselect)
end
protected protected
......
...@@ -432,7 +432,7 @@ def exec_rollback_db_transaction #:nodoc: ...@@ -432,7 +432,7 @@ def exec_rollback_db_transaction #:nodoc:
# In the simple case, MySQL allows us to place JOINs directly into the UPDATE # In the simple case, MySQL allows us to place JOINs directly into the UPDATE
# query. However, this does not allow for LIMIT, OFFSET and ORDER. To support # query. However, this does not allow for LIMIT, OFFSET and ORDER. To support
# these, we must use a subquery. # these, we must use a subquery.
def join_to_update(update, select, key) # :nodoc: def join_to_update(update, select) #:nodoc:
if select.limit || select.offset || select.orders.any? if select.limit || select.offset || select.orders.any?
super super
else else
......
...@@ -371,11 +371,11 @@ def update_all(updates) ...@@ -371,11 +371,11 @@ def update_all(updates)
stmt.set Arel.sql(@klass.send(:sanitize_sql_for_assignment, updates)) stmt.set Arel.sql(@klass.send(:sanitize_sql_for_assignment, updates))
stmt.table(table) stmt.table(table)
stmt.key = table[primary_key]
if joins_values.any? if joins_values.any?
@klass.connection.join_to_update(stmt, arel, table[primary_key]) @klass.connection.join_to_update(stmt, arel)
else else
stmt.key = table[primary_key]
stmt.take(arel.limit) stmt.take(arel.limit)
stmt.order(*arel.orders) stmt.order(*arel.orders)
stmt.wheres = arel.constraints stmt.wheres = arel.constraints
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册