Symfony: Difference between @UniqueEntity and @UniqueConstraint
3 April 2023 (Updated 3 April 2023)
On this page
In a nutshell
@UniqueEntity
is a Symfony annotation used to validate at the application-layer that a particular field or fields is unique to an entity.
@UniqueConstraint
is a Doctrine annotation used to validate at the database-layer that a particular field or fields is unique to a table. It will generate a unique index at the SQL level.
Which to use?
Use both. You want to validate at both the application and database layers.
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment