提交 59a03095 编写于 作者: R Ryuta Kamizono

`join_to_delete` is same as `join_to_update`

上级 f39aa4dd
......@@ -344,18 +344,12 @@ def sanitize_limit(limit)
# 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
# an UPDATE statement, so in the MySQL adapters we redefine this to do that.
def join_to_update(update, select) #:nodoc:
key = update.key
def join_to_update(update, select, key) # :nodoc:
subselect = subquery_for(key, select)
update.where key.in(subselect)
end
def join_to_delete(delete, select, key) #:nodoc:
subselect = subquery_for(key, select)
delete.where key.in(subselect)
end
alias join_to_delete join_to_update
protected
......
......@@ -432,7 +432,7 @@ def exec_rollback_db_transaction #:nodoc:
# 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
# these, we must use a subquery.
def join_to_update(update, select) #:nodoc:
def join_to_update(update, select, key) # :nodoc:
if select.limit || select.offset || select.orders.any?
super
else
......
......@@ -371,11 +371,11 @@ def update_all(updates)
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)
@klass.connection.join_to_update(stmt, arel, table[primary_key])
else
stmt.key = table[primary_key]
stmt.take(arel.limit)
stmt.order(*arel.orders)
stmt.wheres = arel.constraints
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册