validates_uniqueness_of should honor the collation #13465

Open
wants to merge 1 commit into
from

Conversation

Projects
None yet
6 participants
@shugo
Contributor

shugo commented Dec 24, 2013

Currently, if the case_sensitive option of validates_uniqueness_of is omitted, true is used by default.
However, the default collation of MySQL for rake db:create:all in Rails is utf8_unicode_ci, which means that you need to specify case_sensitive: false for each validates_uniqueness_of, except when the collation is explicitly set to *_bin. Otherwise, a DB-level unique constraint violation may occur even if the AR-level validation succeeded.

In MySQL each column has its own collation, and the preferred case sensitivity can be guessed from the value of the collation. Why not use the guessed value as the default?

+ def case_sensitive?
+ true
+ end
+

This comment has been minimized.

Show comment Hide comment
@vipulnsward

vipulnsward Dec 24, 2013

Member

Is it case-sensitive by default for all adapters?

@vipulnsward

vipulnsward Dec 24, 2013

Member

Is it case-sensitive by default for all adapters?

This comment has been minimized.

Show comment Hide comment
@shugo

shugo Dec 24, 2013

Contributor

Yes, it is. An adapter should override it, if necessary.

@shugo

shugo Dec 24, 2013

Contributor

Yes, it is. An adapter should override it, if necessary.

@dijonkitchen

This comment has been minimized.

Show comment Hide comment
@dijonkitchen

dijonkitchen Jan 21, 2017

Contributor

Is this still relevant? Otherwise, it's stale and should be closed.

Contributor

dijonkitchen commented Jan 21, 2017

Is this still relevant? Otherwise, it's stale and should be closed.

@kamipo kamipo added the activerecord label Sep 3, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment