Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Rails 3.0.3 - validates_uniqueness_of case_sensitive fails on UTF8 fields

#6691

Hi,

Sorry if this has been fixed in a later release, or is an issue in MySQL, but I'm experiencing an issue with validates_uniqueness_of in my app. Specifically, when I try to violate the rule the validation does not return an error.

Database is MYSQL 5.0.1 (have tried on later versions as well)
Rails Version is 3.0.3
Ruby Version = 1.9.2p180
Connection encoding is; UTF8
MySQL collation on table / field is: utf8_general_ci
Platforms are Windows and Linux

Example code:

On my User model:

validates_uniqueness_of :login

In Rails console I find a user record and set it's login to a login that's in use on another record. Then check user.valid? and it's true when it should be false.

The validator emits the following statement:

SELECT users.id FROM users WHERE (users.login = BINARY 'my-dupe-id') AND (users.id <> 66664) LIMIT 1

This query returns no results.

Adding the :case_sensitive => true option gets things working as the validator is forcing both values to LOWER() and not using the BINARY qualifier.

Again, sorry if this is something wrong with MySQL (as in the product of how I have the database set up) and thanks for reading this and supporting Rails.

Shawn

Reported by Shawn · April 9th, 2011 @ 12:35 AM

State: new
Milestone: none
Assigned to: nobody
Importance: none

Activity

No comments yet.