Symfony - 更新唯一列 - 验证问题 [英] Symfony - updating unique column - validation problem

查看:26
本文介绍了Symfony - 更新唯一列 - 验证问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Symfony 框架的新手,遇到了表单验证问题.

I'm new to Symfony Framework and I ran into a problem with form validation.

我想更新数据库中包含唯一列的数据,但如果唯一列不变,则返回错误(具有相同域"的对象已经存在.".域列必须是唯一的,但用户应该是可以更改.所以,如果一个用户保存了他的域名,其他人就不能使用它,但他以后可以更改.

I want to update data in DB including unique column, but if unique column is unchanged, an error is returned (An object with the same "domain" already exist."). Domain column must be unique, but user should be able to change it. So, if one user saves his domain name, no one else can use it, but he can change it in future.

似乎表单验证不仅将唯一列与其他行进行比较,而且还将其与自身进行比较.因此,如果用户不更改列并保存表单,则会返回错误.

It seems like form validation compares unique column not only to other rows, but to itself too. So if user don't change the column and saves form, error is returned.

我应该使用什么验证来保留列的唯一性,但可以自由更改?

What validation should I use to preserve column unique, but free to change?

推荐答案

如果你使用 Doctrine 并且验证器是 sfValidatorDoctrineUnique,它应该按预期工作.

If you are using Doctrine and the validator is sfValidatorDoctrineUnique, it should work as intended.

即验证您是否正在更新对象.见第 102 行.

i.e validates if you are updating an object. See line 102.

这篇关于Symfony - 更新唯一列 - 验证问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆