mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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?`.
This commit is contained in:
parent
d59dc69f84
commit
04d0e3c30b
3 changed files with 9 additions and 13 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue