I was previously using where(username: usernames)
to take an array of usernames like and return an ActiveRecord::Relation of users. I've since created an Index on lower(username) and replaced User#find_by_username with the following:
def self.find_by_username(username)
where("lower(username) = ?", username.downcase).first
end
This fails:
def self.find_by_usernames(usernames)
where("lower(username) = ?", usernames.map(&:downcase))
end
It works when it's an array of one username, but not for multiple usernames. It generates SQL like "SELECT \"users\".* FROM \"users\" WHERE (lower(username) = 'joshsmith','vendiddy')"