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