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

时间:2017-08-08 10:20:06

标签: coldfusion entity 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字段设置为标识和主键。问题是我想将串行字段设置为唯一键..有没有办法将此字段设置为唯一键?

1 个答案:

答案 0 :(得分:1)

您是否尝试过如下定义:

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