Как установить сущность как уникальный ключ в 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 устанавливается как идентификатор и как первичный ключ. проблема в том, что я хочу установить серийное поле как уникальный ключ. Есть ли способ установить это поле как уникальный ключ?


person Sudarsono Sung    schedule 08.08.2017    source источник


Ответы (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
person Yieng Ly    schedule 08.08.2017