diff options
-rw-r--r-- | lib/arel/engines/sql/compilers/mysql_compiler.rb | 3 | ||||
-rw-r--r-- | lib/arel/engines/sql/relations/compiler.rb | 10 | ||||
-rw-r--r-- | lib/arel/engines/sql/relations/writes.rb | 12 |
3 files changed, 15 insertions, 10 deletions
diff --git a/lib/arel/engines/sql/compilers/mysql_compiler.rb b/lib/arel/engines/sql/compilers/mysql_compiler.rb index e3cf1f2add..ba3312ba72 100644 --- a/lib/arel/engines/sql/compilers/mysql_compiler.rb +++ b/lib/arel/engines/sql/compilers/mysql_compiler.rb @@ -1,6 +1,9 @@ module Arel module SqlCompiler class MySQLCompiler < GenericCompiler + def limited_update_conditions(conditions) + conditions + end end end end diff --git a/lib/arel/engines/sql/relations/compiler.rb b/lib/arel/engines/sql/relations/compiler.rb index b85d227705..46f728a7bd 100644 --- a/lib/arel/engines/sql/relations/compiler.rb +++ b/lib/arel/engines/sql/relations/compiler.rb @@ -21,6 +21,16 @@ module Arel ("#{locked}" unless locked.blank?) end + def limited_update_conditions(conditions) + begin + quote_primary_key = engine.quote_column_name(table.name.classify.constantize.primary_key) + rescue NameError + quote_primary_key = engine.quote_column_name("id") + end + + "WHERE #{quote_primary_key} IN (SELECT #{quote_primary_key} FROM #{engine.connection.quote_table_name table.name} #{conditions})" + end + protected def method_missing(method, *args, &block) relation.send(method, *args, &block) diff --git a/lib/arel/engines/sql/relations/writes.rb b/lib/arel/engines/sql/relations/writes.rb index 83c5fbad42..30b36ddda8 100644 --- a/lib/arel/engines/sql/relations/writes.rb +++ b/lib/arel/engines/sql/relations/writes.rb @@ -5,7 +5,7 @@ module Arel "DELETE", "FROM #{table_sql}", ("WHERE #{wheres.collect(&:to_sql).join(' AND ')}" unless wheres.blank? ), - ("LIMIT #{taken}" unless taken.blank? ) + ("LIMIT #{taken}" unless taken.blank? ) end end @@ -69,15 +69,7 @@ module Arel unless taken.blank? conditions << " LIMIT #{taken}" - if engine.adapter_name != "MySQL" - begin - quote_primary_key = engine.quote_column_name(table.name.classify.constantize.primary_key) - rescue NameError - quote_primary_key = engine.quote_column_name("id") - end - - conditions = "WHERE #{quote_primary_key} IN (SELECT #{quote_primary_key} FROM #{engine.connection.quote_table_name table.name} #{conditions})" - end + conditions = compiler.limited_update_conditions(conditions) end conditions |