diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-03-04 22:40:43 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-04 22:40:43 +0900 |
commit | 467ae9c82b02769b2990e9dbd9e12102e90a17dd (patch) | |
tree | 32ff637ba806db7bb15b32abf99b685fb2bae525 /activerecord/lib/active_record | |
parent | cbedbdef0708e00968d66feab89c86a40f2292e0 (diff) | |
parent | 9def05385f1cfa41924bb93daa187615e88c95b9 (diff) | |
download | rails-467ae9c82b02769b2990e9dbd9e12102e90a17dd.tar.gz rails-467ae9c82b02769b2990e9dbd9e12102e90a17dd.tar.bz2 rails-467ae9c82b02769b2990e9dbd9e12102e90a17dd.zip |
Merge pull request #35350 from kamipo/deprecate_validate_uniqueness_mismatched_collation
Deprecate mismatched collation comparison for uniquness validator
Diffstat (limited to 'activerecord/lib/active_record')
3 files changed, 16 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index f205d77ddb..823efee301 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -506,7 +506,7 @@ module ActiveRecord @connection end - def default_uniqueness_comparison(attribute, value) # :nodoc: + def default_uniqueness_comparison(attribute, value, klass) # :nodoc: case_sensitive_comparison(attribute, value) end diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index 37506a97e2..96f902792e 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -453,6 +453,20 @@ module ActiveRecord SQL end + def default_uniqueness_comparison(attribute, value, klass) # :nodoc: + column = column_for_attribute(attribute) + + if column.collation && !column.case_sensitive? + ActiveSupport::Deprecation.warn(<<~MSG.squish) + Uniqueness validator will no longer enforce case sensitive comparison in Rails 6.1. + To continue case sensitive comparison on the :#{attribute.name} attribute in #{klass} model, + pass `case_sensitive: true` option explicitly to the uniqueness validator. + MSG + end + + super + end + def case_sensitive_comparison(attribute, value) # :nodoc: column = column_for_attribute(attribute) diff --git a/activerecord/lib/active_record/validations/uniqueness.rb b/activerecord/lib/active_record/validations/uniqueness.rb index 88ae62c681..dc1be73a60 100644 --- a/activerecord/lib/active_record/validations/uniqueness.rb +++ b/activerecord/lib/active_record/validations/uniqueness.rb @@ -63,7 +63,7 @@ module ActiveRecord if bind.nil? attr.eq(bind) elsif !options.key?(:case_sensitive) - klass.connection.default_uniqueness_comparison(attr, bind) + klass.connection.default_uniqueness_comparison(attr, bind, klass) elsif options[:case_sensitive] klass.connection.case_sensitive_comparison(attr, bind) else |