0

Flow 支持这样的事情吗?

/**
 * @ORM\Entity
 * @UniqueEntity(
 *     fields={"host", "port"},
 *     errorPath="port",
 *     message="This port is already in use on that host."
 * )
 */
class Service
{

我需要验证一个标题没有为一个用户使用两次。

编辑:添加了模型验证器来检查唯一性,但现在它已检查所有操作:加载、更新等。

编辑 2:如果对象是新的(尚未持久化),则通过签入验证器来“解决”。更新已经存在的实体时仍然存在问题。

4

1 回答 1

1

您可以使用 UniqueEntityValidator 并仅在需要检查唯一性的操作中注释验证器。 http://flowframework.readthedocs.org/en/latest/TheDefinitiveGuide/PartV/ValidatorReference.html#uniqueentityvalidator

或者,您可以使用 ValidationGroups 仅在您希望它发生的地方使用现有模型验证器进行验证。 http://flowframework.readthedocs.org/en/latest/TheDefinitiveGuide/PartIII/Validation.html?highlight=validationgroups#advanced-feature-partial-validation

于 2015-09-03T23:30:43.610 回答