Permalink
Browse files

Consistently use LOWER() for uniqueness validations (rather than mixi…

…ng with UPPER()) so the database can always use a functional index on the lowercased column. Closes #6495.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5434 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 7b453d2 commit 5b979ed8ffe5f42747141f632656571f0fd194bf @jeremy jeremy committed Nov 5, 2006
Showing with 4 additions and 2 deletions.
  1. +2 −0 activerecord/CHANGELOG
  2. +2 −2 activerecord/lib/active_record/validations.rb
View
2 activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Consistently use LOWER() for uniqueness validations (rather than mixing with UPPER()) so the database can always use a functional index on the lowercased column. #6495 [Si]
+
* SQLite: fix calculations workaround, remove count(distinct) query rewrite, cleanup test connection scripts. [Jeremy Kemper]
* SQLite: count(distinct) queries supported in >= 3.2.6. #6544 [Bob Silva]
View
4 activerecord/lib/active_record/validations.rb
@@ -533,8 +533,8 @@ def validates_uniqueness_of(*attr_names)
condition_sql = "#{record.class.table_name}.#{attr_name} #{attribute_condition(value)}"
condition_params = [value]
else
- condition_sql = "UPPER(#{record.class.table_name}.#{attr_name}) #{attribute_condition(value)}"
- condition_params = [value.upcase]
+ condition_sql = "LOWER(#{record.class.table_name}.#{attr_name}) #{attribute_condition(value)}"
+ condition_params = [value.downcase]
end
if scope = configuration[:scope]
Array(scope).map do |scope_item|

0 comments on commit 5b979ed

Please sign in to comment.