Does Active Record provide a way to generate SQL that forces a text search to be case-sensitive?
Ruby-on-Rails generators instructed to create a string-type column produce a simple VARCHAR(255)
field, in a mysql
database. It turns out that queries on such columns are case insensitive by default.
Thus, an Active Record search such as:
Secret.where(token: 'abcde')
will match records with tokens abcde
, ABcdE
, etc.
Without changing the underlying database column (e.g. specifying a utf8_bin
collation) searches can be made case sensitive by explicitly tweaking the where
clause:
Secret.where('binary token = ?', 'abcde')
However, this is database-specific, and I am wondering if Active Record has an idiom to accomplish the same for any database. Just as an example, something resembling the where.not
construct:
Secret.where.binary(token: 'abcde')
Wouldn't this be a common enough need?