symfony/symfony-docs — Issue #873: Some Documentation for UniqueEntity constraint
Author: keymaster
Created: 2011-11-23 12:39:52+00:00
State: open

The following should be added:

First, you also need to add a use statement to your entity as follows:

use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;

Second, in your xml file, the constraint is specified a little differently than other constraints. The constraint tag is not placed within the tag, but is right under the class tag, at the same level as the property tag.

Third, in your constraint tag, you need to specify the full pathname to the constraint . You can't just say UniqueEntity.

Finally, if you want multiple fields within the entity to be unique, you need separate constraint tags.

Here is an example:
```

email

This email already exists.

phone

This phone number already exists.

website

This website already exists.

```