From 320996a7e5dbf0014b37cfc4d2259c88a4092744 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Sat, 6 Aug 2016 21:00:46 +0900 Subject: [PATCH] Revert passing arel node with splat binds for `where` Passing arel node with splat binds for `where` was introduced at #22877 for uniqueness validator supports prepared statement. But I'd not like to introduce the following usage: ```ruby Foo.where(arel, *binds) ``` I'd like to revert this internal usage. --- .../lib/active_record/relation/where_clause_factory.rb | 1 - activerecord/lib/active_record/validations/uniqueness.rb | 7 +++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/activerecord/lib/active_record/relation/where_clause_factory.rb b/activerecord/lib/active_record/relation/where_clause_factory.rb index dbf172a577..a81ff98e49 100644 --- a/activerecord/lib/active_record/relation/where_clause_factory.rb +++ b/activerecord/lib/active_record/relation/where_clause_factory.rb @@ -22,7 +22,6 @@ module ActiveRecord parts = predicate_builder.build_from_hash(attributes) when Arel::Nodes::Node parts = [opts] - binds = other else raise ArgumentError, "Unsupported argument type: #{opts} (#{opts.class})" end diff --git a/activerecord/lib/active_record/validations/uniqueness.rb b/activerecord/lib/active_record/validations/uniqueness.rb index 58273509be..8c4930a81d 100644 --- a/activerecord/lib/active_record/validations/uniqueness.rb +++ b/activerecord/lib/active_record/validations/uniqueness.rb @@ -76,8 +76,11 @@ module ActiveRecord else klass.connection.case_sensitive_comparison(table, attribute, column, value) end - bind = Relation::QueryAttribute.new(attribute_name, value, cast_type) - klass.unscoped.where!(comparison, bind) + klass.unscoped.tap do |scope| + parts = [comparison] + binds = [Relation::QueryAttribute.new(attribute_name, value, cast_type)] + scope.where_clause += Relation::WhereClause.new(parts, binds) + end end def scope_relation(record, relation)