This project is archived and is in readonly mode.

#4909 ✓resolved
ara.t.howard

validates_uniqueness_of does not quote scoped column names and then barfs

Reported by ara.t.howard | June 20th, 2010 @ 01:33 AM | in 2.3.9

column isn't quoted when it's from a scope column. this makes any reserved word liek 'group' blow up.

this is a silly bug that breaks any code where the column name of a
scope is a reserved word (like group):

cfp:/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.8 > diff -buB
lib/active_record/validations.rb.org lib/active_record/validations.rb

--- lib/active_record/validations.rb.org        2010-06-19
09:38:42.000000000 -0600
+++ lib/active_record/validations.rb    2010-06-19 09:39:01.000000000
-0600
@@ -825,7 +825,7 @@
           if scope = configuration[:scope]
             Array(scope).map do |scope_item|
               scope_value = record.send(scope_item)
-              condition_sql << " AND " <<
attribute_condition("#{record.class.quoted_table_name}.#{scope_item}",
scope_value)
+              condition_sql << " AND " <<
attribute_condition("#{record.class.quoted_table_name}.#{connection.quote_column_name(scope_item)}",
scope_value)
               condition_params << scope_value
             end
           end

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages