I have something like:
class User
include DataMapper::Resource
property :id, Serial
property :username, Text
end
I want usernames to be case-sensitive, so users can make usernames as they choose. What’s the best way to then search for usernames in a case-insensitive way?
if I make a user named ‘TestUser’, I want to be able to access it with something like
User.first(:username => 'testuser')
I thought about making a username_downcased property that uses a validates_with_method to make a downcased version of the username property for indexing, but I had problems getting that to work.
After a bit of finagling I found a solution, but I would be very surprised if it is the best one.
Case-sensitive name stored in username, but case-insensitive indexing can be done on username_lower.