Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move update conditions with limit logic into compilers.

  • Loading branch information...
commit f21f289ebf8cd4b89f507d48e62e7c5c986922d8 1 parent 7dc7cd5
@miloops miloops authored
View
3  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
View
10 lib/arel/engines/sql/relations/compiler.rb
@@ -21,6 +21,16 @@ def select_sql
("#{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)
View
12 lib/arel/engines/sql/relations/writes.rb
@@ -5,7 +5,7 @@ def to_sql
"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 @@ def build_update_conditions_sql
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
Please sign in to comment.
Something went wrong with that request. Please try again.