activerecord-2.3.5/lib/active_record/validations.rb 774 def validates_uniqueness_of(*attr_names) 775 configuration = { :case_sensitive => true }
This explains some issues with exceptions being raised from MySql where we had a unique database index on a column, but we were validating with the default "validates_uniqueness_of".
One additional note on this. Making :case_sensitive => false changes the MySql query to
WHERE LOWER(table_name.column_name) = BINARY 'value'
Which will bypass the benefit of a database index on write. You'll still get the benefits of the index on read operations.
There is quite a lot of discussion around this issue in this lighthouse case. It's not a simple issue.
There are some patches to move around this issue for 2.3 involve detecting the database exceptions on index exceptions, foreign key exceptions and adding them into ActiveRecord errors. Which is a much nicer approach I think. Can see them here and here.
In Rails 3 the validations issue should be much simpler. The new validations code is so much more readable. And custom validation classes look really useful.
http://lindsaar.net/2010/1/31/validates_rails_3_awesome_is_true
No comments:
Post a Comment