diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2016-01-01 06:18:03 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2016-01-01 07:33:54 +0900 |
commit | b80d304f11f14643fb0f7b503d973c62a94fb20d (patch) | |
tree | c347329ec5058cfa314f8a96609e0918c493872a /activerecord/lib/active_record/validations | |
parent | 8167fa4562841f4ae7ce307ce0c91a448a695ad9 (diff) | |
download | rails-b80d304f11f14643fb0f7b503d973c62a94fb20d.tar.gz rails-b80d304f11f14643fb0f7b503d973c62a94fb20d.tar.bz2 rails-b80d304f11f14643fb0f7b503d973c62a94fb20d.zip |
Refactor `case_{sensitive|insensitive}_comparison`
Before:
```
SELECT 1 AS one FROM "topics" WHERE "topics"."title" = 'abc' LIMIT $1 [["LIMIT", 1]]
```
After:
```
SELECT 1 AS one FROM "topics" WHERE "topics"."title" = $1 LIMIT $2 [["title", "abc"], ["LIMIT", 1]]
```
Diffstat (limited to 'activerecord/lib/active_record/validations')
-rw-r--r-- | activerecord/lib/active_record/validations/uniqueness.rb | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/validations/uniqueness.rb b/activerecord/lib/active_record/validations/uniqueness.rb index edc1325b25..a376e2a17f 100644 --- a/activerecord/lib/active_record/validations/uniqueness.rb +++ b/activerecord/lib/active_record/validations/uniqueness.rb @@ -73,15 +73,18 @@ module ActiveRecord value = value.to_s[0, column.limit] end - value = Arel::Nodes::Quoted.new(value) - comparison = if !options[:case_sensitive] && !value.nil? # will use SQL LOWER function before comparison, unless it detects a case insensitive collation klass.connection.case_insensitive_comparison(table, attribute, column, value) else klass.connection.case_sensitive_comparison(table, attribute, column, value) end - klass.unscoped.where(comparison) + if value.nil? + klass.unscoped.where(comparison) + else + bind = Relation::QueryAttribute.new(attribute.to_s, value, Type::Value.new) + klass.unscoped.where(comparison, bind) + end rescue RangeError klass.none end |