如何在 ColdBox 中将实体设置为唯一键

How to set entity as unique Key in ColdBox

我正在 ColdBox 中创建模型实体。

component persistent="true" {
  property name="id" type="int" fieldType="id"  generator="increment";
  property name="stamptime" type="timestamp";
  property name="type" type="string" length="1" sqltype="varchar(1)";
  property name="serial" type="string" length="100" sqltype="varchar(100)";}

id 字段设置为标识和主键。问题是我想将序列字段设置为唯一键。有什么方法可以将此字段设置为唯一键吗?

您是否试过在 属性 中定义如下:

component persistent="true" {
  property name="serial" type="string" length="100" sqltype="varchar(100)" unique="true";

  // and / or as a validation via constraints?
  this.constraints = {
    serial = { unique=true };
  } //constraints
} //component