diff options
author | Emilio Tagua <miloops@gmail.com> | 2010-02-16 10:29:23 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2010-02-16 10:29:23 -0300 |
commit | f21f289ebf8cd4b89f507d48e62e7c5c986922d8 (patch) | |
tree | 1472d42af38aab6c3022132a9a115fd5766410d1 /lib/arel | |
parent | 7dc7cd5d6dffae18b41c07ac5c6e291d0ea8cd74 (diff) | |
download | rails-f21f289ebf8cd4b89f507d48e62e7c5c986922d8.tar.gz rails-f21f289ebf8cd4b89f507d48e62e7c5c986922d8.tar.bz2 rails-f21f289ebf8cd4b89f507d48e62e7c5c986922d8.zip |
Move update conditions with limit logic into compilers.
Diffstat (limited to 'lib/arel')
-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 |