aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2016-02-22 01:09:10 +0900
committerRyuta Kamizono <kamipo@gmail.com>2016-08-06 20:43:13 +0900
commit04d0e3c30b877a75cd7e82d3d41422b879a17e64 (patch)
treeb8b8d5abbb4d892f2bb58b53966f6818164958b3 /activerecord/lib
parentd59dc69f847bff13bb85a571c8cf1512cd067d92 (diff)
downloadrails-04d0e3c30b877a75cd7e82d3d41422b879a17e64.tar.gz
rails-04d0e3c30b877a75cd7e82d3d41422b879a17e64.tar.bz2
rails-04d0e3c30b877a75cd7e82d3d41422b879a17e64.zip
Don't passing a nil value to `case_sensitive_comparison`
A `value` is only used for checking `value.nil?`. It is unnecessary if immediately return when `value.nil?`.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_adapter.rb6
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb2
-rw-r--r--activerecord/lib/active_record/validations/uniqueness.rb14
3 files changed, 9 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
index 0b8bacff4e..0c99c00e78 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -434,11 +434,7 @@ module ActiveRecord
end
def case_sensitive_comparison(table, attribute, column, value)
- if value.nil?
- table[attribute].eq(value)
- else
- table[attribute].eq(Arel::Nodes::BindParam.new)
- end
+ table[attribute].eq(Arel::Nodes::BindParam.new)
end
def case_insensitive_comparison(table, attribute, column, value)
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 5e9705e02f..85321e825a 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -614,7 +614,7 @@ module ActiveRecord
end
def case_sensitive_comparison(table, attribute, column, value)
- if !value.nil? && column.collation && !column.case_sensitive?
+ if column.collation && !column.case_sensitive?
table[attribute].eq(Arel::Nodes::Bin.new(Arel::Nodes::BindParam.new))
else
super
diff --git a/activerecord/lib/active_record/validations/uniqueness.rb b/activerecord/lib/active_record/validations/uniqueness.rb
index 608d072e48..58273509be 100644
--- a/activerecord/lib/active_record/validations/uniqueness.rb
+++ b/activerecord/lib/active_record/validations/uniqueness.rb
@@ -55,6 +55,10 @@ module ActiveRecord
value = value.attributes[reflection.klass.primary_key] unless value.nil?
end
+ if value.nil?
+ return klass.unscoped.where!(attribute => value)
+ end
+
# the attribute may be an aliased attribute
if klass.attribute_alias?(attribute)
attribute = klass.attribute_alias(attribute)
@@ -66,18 +70,14 @@ module ActiveRecord
column = klass.columns_hash[attribute_name]
cast_type = klass.type_for_attribute(attribute_name)
- comparison = if !options[:case_sensitive] && !value.nil?
+ comparison = if !options[:case_sensitive]
# 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
- if value.nil?
- klass.unscoped.where(comparison)
- else
- bind = Relation::QueryAttribute.new(attribute_name, value, cast_type)
- klass.unscoped.where(comparison, bind)
- end
+ bind = Relation::QueryAttribute.new(attribute_name, value, cast_type)
+ klass.unscoped.where!(comparison, bind)
end
def scope_relation(record, relation)