Unique values for two columns in Doctrine
I have an object called Dimension. It has three attributes: ID, Width and Height. The identifier is the primary key. The size must be unique in the table, therefore there must be only one record with a given size (for example, 40x30). What restrictions do I need to set? Is it correct uniqueConstraints={@UniqueConstraint(name="dimension", columns={"width", "height"})}
?
source to share
From the documentation,
@ UnicConstraint annotations are used inside the @Table annotation at the entity-class level. This allows SchemaTool to hint at creating a unique database constraint for the specified table columns. It only matters in the context of generating a SchemaTool.
Required attributes:
- name: index name
- : array of columns.
Anders then YES
/**
* @Entity
* @Table(name="xxx",uniqueConstraints={@UniqueConstraint(name="dimension", columns={"width", "height"})})
*/
class Dimension
must complete the task.
source to share