Skip to content

Commit 0d12708

Browse files
authored
Merge pull request rails#26073 from kamipo/revert_passing_splat_binds_for_arel_node
Revert passing arel node with splat binds for `where`
2 parents c53102b + 320996a commit 0d12708

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

activerecord/lib/active_record/connection_adapters/abstract_adapter.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -434,11 +434,7 @@ def raw_connection
434434
end
435435

436436
def case_sensitive_comparison(table, attribute, column, value)
437-
if value.nil?
438-
table[attribute].eq(value)
439-
else
440-
table[attribute].eq(Arel::Nodes::BindParam.new)
441-
end
437+
table[attribute].eq(Arel::Nodes::BindParam.new)
442438
end
443439

444440
def case_insensitive_comparison(table, attribute, column, value)

activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ def primary_keys(table_name) # :nodoc:
614614
end
615615

616616
def case_sensitive_comparison(table, attribute, column, value)
617-
if !value.nil? && column.collation && !column.case_sensitive?
617+
if column.collation && !column.case_sensitive?
618618
table[attribute].eq(Arel::Nodes::Bin.new(Arel::Nodes::BindParam.new))
619619
else
620620
super

activerecord/lib/active_record/relation/where_clause_factory.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ def build(opts, other)
2222
parts = predicate_builder.build_from_hash(attributes)
2323
when Arel::Nodes::Node
2424
parts = [opts]
25-
binds = other
2625
else
2726
raise ArgumentError, "Unsupported argument type: #{opts} (#{opts.class})"
2827
end

activerecord/lib/active_record/validations/uniqueness.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ def build_relation(klass, attribute, value) # :nodoc:
5555
value = value.attributes[reflection.klass.primary_key] unless value.nil?
5656
end
5757

58+
if value.nil?
59+
return klass.unscoped.where!(attribute => value)
60+
end
61+
5862
# the attribute may be an aliased attribute
5963
if klass.attribute_alias?(attribute)
6064
attribute = klass.attribute_alias(attribute)
@@ -66,17 +70,16 @@ def build_relation(klass, attribute, value) # :nodoc:
6670
column = klass.columns_hash[attribute_name]
6771
cast_type = klass.type_for_attribute(attribute_name)
6872

69-
comparison = if !options[:case_sensitive] && !value.nil?
73+
comparison = if !options[:case_sensitive]
7074
# will use SQL LOWER function before comparison, unless it detects a case insensitive collation
7175
klass.connection.case_insensitive_comparison(table, attribute, column, value)
7276
else
7377
klass.connection.case_sensitive_comparison(table, attribute, column, value)
7478
end
75-
if value.nil?
76-
klass.unscoped.where(comparison)
77-
else
78-
bind = Relation::QueryAttribute.new(attribute_name, value, cast_type)
79-
klass.unscoped.where(comparison, bind)
79+
klass.unscoped.tap do |scope|
80+
parts = [comparison]
81+
binds = [Relation::QueryAttribute.new(attribute_name, value, cast_type)]
82+
scope.where_clause += Relation::WhereClause.new(parts, binds)
8083
end
8184
end
8285

0 commit comments

Comments
 (0)