On Saturday, July 7, 2012 4:25:31 PM UTC-7, cult hero wrote:
>
> I've been looking for the best way to deal with that amounts to a case 
> insensitive column in PostgreSQL. (It stores email addresses.) I've found a 
> couple of options (an index using lower() and triggers using lower()) but 
> is there some way to make validates_unique do so in an insensitive manner? 
> That way is [email protected] is entered, [email protected] will still 
> anger the validation gods. Or do I need to make my own validation for this?


In PostgreSQL, you'd add a unique constraint/index on lower(email).  
Assuming you don't care if the case is preserved, you could always just 
lower case the email on input.  If you do need the case preserved, I don't 
think validates_unique will work without modifications.  It would need to 
accept an additional option at the least (:something like :where=>proc{|ds| 
...} that would be used instead of the default WHERE conditions).

You can probably use a hack like this if the model dataset is not already 
filtered:

  validates_unique(:email){|ds| ds.opts[:where].args.map!{|x| 
Sequel.function(:lower, x)}; ds}

Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sequel-talk/-/xPJcfePToUcJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to