原则中两列的唯一值 [英] Unique values for two columns in Doctrine

查看:151
本文介绍了原则中两列的唯一值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为Dimension的实体。它有三个属性 - ID,宽度和高度。
ID是主键。在表中,维应该是唯一的,所以必须只有一个记录与给定维度(例如40x30)。我需要设定什么限制?
uniqueConstraints = {@ UniqueConstraint(name =dimension,columns = {width,height})} 正确?

解决方案

文档


@UniqueConstraint在
的实体级别的@Table注释中使用注释。它允许提示SchemaTool在指定的表列上生成
数据库唯一约束。在SchemaTool模式生成环境中只有
的意思。



必需属性:




  • name:索引名称

  • 列:列数组。


然后,anwser YES

  / ** 
* @Entity
* @Table(name =xxx,uniqueConstraints = {@ UniqueConstraint(name =dimension,columns = {width,height})})
* /
class Dimension

应该做这个工作。


I have entity called Dimension. It has three attributes - ID, width and height. ID is primary key. In the table, the dimension should be unique so there has to be only one record with given dimension (for example 40x30). What constraints I need to set? Is uniqueConstraints={@UniqueConstraint(name="dimension", columns={"width", "height"})} correct?

解决方案

From the documentation,

@UniqueConstraint annotation is used inside the @Table annotation on the entity-class level. It allows to hint the SchemaTool to generate a database unique constraint on the specified table columns. It only has meaning in the SchemaTool schema generation context.

Required attributes:

  • name: Name of the Index
  • columns: Array of columns.

The anwser is then YES

/**
 * @Entity
 * @Table(name="xxx",uniqueConstraints={@UniqueConstraint(name="dimension", columns={"width", "height"})})
 */
class Dimension

should then do the job.

这篇关于原则中两列的唯一值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆