2012-07-05 53 views
0

新中的Grails 2.0,並希望創造在評價一個自定義驗證該客戶ID是客戶的任何幫助。只有現有客戶才能完成評估。謝謝!Grails的自定義驗證的房產從另一個域類

一流的客戶{

String custId 
String firstName 
String lastName 

static constraints = { 
    custId() 
    firstName() 
    lastName() 
} 

}

評課{

String custId 
String comment 

static constraints = { 
    custId() 
    comment() 
} 

}

回答

0

我建議輕微的重新設計,並通過客戶的實例,爲你的評價對象。然後在Evaluation類中,創建一個驗證以確保Customer不爲null。這樣做是利用Customer類的驗證,以確保你有一個「有效的」客戶ID,你需要有,以便從custId中查找/實例化一個Customer對象,我假設你從Web獲得表格正在提交。

class Evaluation { 
    Customer customer 
    String comment 

    static constraints = { 
    customer nullable: false 
    } 
}