diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-12-17 02:07:27 -0200 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-12-17 02:07:27 -0200 |
commit | 5082cce6e3de01f54af620c590055ebb1effa299 (patch) | |
tree | f580abf737de8d78b6e6cb882379befd7d7761dc /activerecord/lib | |
parent | 4d06ea9a829de8f6f5a345589828e182eacab6a3 (diff) | |
download | rails-5082cce6e3de01f54af620c590055ebb1effa299.tar.gz rails-5082cce6e3de01f54af620c590055ebb1effa299.tar.bz2 rails-5082cce6e3de01f54af620c590055ebb1effa299.zip |
Revert "Merge pull request #22615 from kamipo/join_to_delete_is_same_as_join_to_update"
This reverts commit 4d06ea9a829de8f6f5a345589828e182eacab6a3, reversing
changes made to e9d15072a94e2ae4dec5b7a121c84a5db38547b8.
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
Diffstat (limited to 'activerecord/lib')
3 files changed, 11 insertions, 5 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 3d05f52736..848aeb821c 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb @@ -344,12 +344,18 @@ module ActiveRecord # 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, key) # :nodoc: + def join_to_update(update, select) #:nodoc: + key = update.key subselect = subquery_for(key, select) update.where key.in(subselect) 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 diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index 6fddfb5347..25ba42e5c9 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -432,7 +432,7 @@ module ActiveRecord # 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, key) # :nodoc: + def join_to_update(update, select) #:nodoc: if select.limit || select.offset || select.orders.any? super else diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 316b0d6308..2cf19c76c5 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -371,11 +371,11 @@ module ActiveRecord 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, table[primary_key]) + @klass.connection.join_to_update(stmt, arel) else - stmt.key = table[primary_key] stmt.take(arel.limit) stmt.order(*arel.orders) stmt.wheres = arel.constraints |