diff options
-rw-r--r-- | activerecord/lib/arel/visitors/mysql.rb | 9 | ||||
-rw-r--r-- | activerecord/lib/arel/visitors/to_sql.rb | 8 |
2 files changed, 8 insertions, 9 deletions
diff --git a/activerecord/lib/arel/visitors/mysql.rb b/activerecord/lib/arel/visitors/mysql.rb index 9d9294fecc..5d10088427 100644 --- a/activerecord/lib/arel/visitors/mysql.rb +++ b/activerecord/lib/arel/visitors/mysql.rb @@ -75,14 +75,7 @@ module Arel # :nodoc: all o end end - - def prepare_delete_statement(o) - if o.offset || has_join_sources?(o) - super - else - o - end - end + alias :prepare_delete_statement :prepare_update_statement # MySQL is too stupid to create a temporary table for use subquery, so we have # to give it some prompting in the form of a subsubquery. diff --git a/activerecord/lib/arel/visitors/to_sql.rb b/activerecord/lib/arel/visitors/to_sql.rb index 7c0f6c2e97..a55450956b 100644 --- a/activerecord/lib/arel/visitors/to_sql.rb +++ b/activerecord/lib/arel/visitors/to_sql.rb @@ -76,7 +76,13 @@ module Arel # :nodoc: all def visit_Arel_Nodes_DeleteStatement(o, collector) o = prepare_delete_statement(o) - collector << "DELETE FROM " + if has_join_sources?(o) + collector << "DELETE " + visit o.relation.left, collector + collector << " FROM " + else + collector << "DELETE FROM " + end collector = visit o.relation, collector collect_where_for(o, collector) |