Hi,
I would like to ask what is the reason behind the fact that
ActiveRecord Uniqueness Validator does the following:
if value.nil? || (options[:case_sensitive] || !column.text?)
sql = "#{sql_attribute} #{operator}"
else
sql = "LOWER(#{sql_attribute}) = LOWER(?)"
end
In other words, why it sends the 'LOWER" when case sensitivity is set
to false (for string attributes)
This generates sql queries that do not use the index on the attribute.
My opinion is that ActiveRecod should just pass the requirement (case
sensitive or not) to adapter (e.g. mysql2) and let the
adapter decide how to do the job/construct the query (which would
probably take into account db colation or do nothing and let db decide
how to handle it)
Moreover, I find it inconsistent the fact that default behaviour
of :uniqueness validator is case sensitive TRUE when finders are all
case insensitive "don't care". Maybe, as a workaround, except from
false and true, you can consider something like :uniqueness =>
{:case_sensitive => :db} and the db colation decide about it.
Currently, I have decided to stop using :uniqueness validator on
string type attributes, because of all this mess with MySQL colation.
Panayotis
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
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/rubyonrails-core?hl=en.