Hi all,
In the aacg_courses model I have:
validates_uniqueness_of :name, :case_sensitive=>:false
in the migration I have an index with :unique options
add_index :aacg_courses,
[:name, :language_id ],:name=>"aacg_courses_idx" , :unique => true
when trying to save a record with a name that differs to one in the
DB by only an accent (or ñ) I get an error:
Mysql::Error: Duplicate entry 'Geografia-8-core-1' for key
'aacg_courses_idx': INSERT INTO aacg_courses (name,
acad_area_cycle_grade_id, type_course, language_id) VALUES
('Geografia', 8, 'core', 1)
The DB had a record with name Geografía (note the accent on the i) and
I was trying to save one without the accent; call them G1 and G2
It seems that validate_uniqueness_of finds G1 and G2 are diff but
MySQL finds they are the same and issues a uniquess violation.
MySQL's behavior is correct in my view as I'm using UTF8/collation
(which ignores accents) throughout in my app.
I have UTF8 in all the right places in Rails I think:
$KCODE = "UTF-8" in environment.rb, and
def configure_charsets
headers["Content-Type"] = "text/html; charset=utf-8"
ActiveRecord::Base.connection.execute 'SET NAMES UTF8'
end
in app/controllers/application_controller
It seems that rails uniqueness is not mached to that of the DB in this
case.
Is there an elegant way of getting this right? [short of writing a
custom validation]
Thanks in advance, Jose
--~--~---------~--~----~------------~-------~--~----~
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
-~----------~----~----~----~------~----~------~--~---