2017-08-08 103 views
0

我在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

您是否嘗試過在屬性定義如下:

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 
相關問題