I have a model that has two fields, which I will call first_name and last_name, and I want to make sure that the combination of the two are case-insensitively unique. I've gotten halfway there by using this:
validates_uniqueness_of :first_name, :scope => :last_name
The problem is that the uniqueness check seems to be case sensitive, even though the documentation says it should be case insensitive by default. So given an existing record:
{ :first_name => 'John', :last_name => 'Smith' }
This will be allowed:
{ :first_name => 'JOHN', :last_name => 'SMITH' }
As well as any additional record where there is any variation of case in either the first or last name. Why are these records being allowed? How can I enforce case insensitive uniqueness across both fields together?
:case_sensitive => false
made it work for the first_name, but it doesn't work the other direction. It will still accept{ :first_name => 'John', :last_name => 'SMITH' }
. Is there a way to make it work bi-directionally? Would I just include twovalidates_uniqueness_of
rules with the field swapped? – Alister