Skip to content
Browse files

quote scoped columns in validates_uniqueness_of [#4909 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent 7d2173e commit 09a23d22908813f4b572d8c676325a12c51cfa9a kane committed with josevalim Jun 22, 2010
View
2 activerecord/lib/active_record/validations.rb
@@ -825,7 +825,7 @@ def validates_uniqueness_of(*attr_names)
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
View
12 activerecord/test/cases/validations_test.rb
@@ -434,6 +434,18 @@ def test_validate_uniqueness_with_scope
end
end
+ def test_validate_uniqueness_with_reserved_word_as_scope
+ repair_validations(Reply) do
+ Topic.validates_uniqueness_of(:content, :scope => "group")
+
+ t1 = Topic.create "title" => "t1", "content" => "hello world2"
+ assert t1.valid?
+
+ t2 = Topic.create "title" => "t2", "content" => "hello world2"
+ assert !t2.valid?
+ end
+ end
+
def test_validate_uniqueness_scoped_to_defining_class
t = Topic.create("title" => "What, me worry?")
View
1 activerecord/test/schema/schema.rb
@@ -460,6 +460,7 @@ def create_table(*args, &block)
t.integer :parent_id
t.string :parent_title
t.string :type
+ t.string :group
end
create_table :taggings, :force => true do |t|

0 comments on commit 09a23d2

Please sign in to comment.
Something went wrong with that request. Please try again.