提交 09a23d22 编写于 作者: K kane 提交者: José Valim

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

Signed-off-by: NJosé Valim <jose.valim@gmail.com>
上级 7d2173ec
......@@ -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
......
......@@ -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?")
......
......@@ -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|
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册