Search code examples
validationsymfonyentityunique

unique entity validation for add and edit forms


I use unique entity validation in username property of user entity, when the user is going to be added that is ok, but when the user is going to be edited, and username is not changed the unique entity validation impede this, because the same object already exist with that username, how can I handle this? PD:sorry for my poor english


Solution

  • Use validations groups. Link your UniqueEntity constraint to a validation group "new", then only link this group to your form when you are creating a User.