我有一个Domain类
class Store{
String name
Store hierarchy
Date dateCreated
Date lastUpdated
static hasMany=[storeRestrictions:StoreRestrictions]
boolean isBillable
boolean isConsignment
boolean isMassUploadPossible
static constraints = {
name(nullable:false,blank:false,maxSize:50,unique:true)
hierarchy(nullable:true,blank:true)
dateCreated()
lastUpdated()
isBillable()
isMassUploadPossible()
storeRestrictions(nullable:false)
}
}
有没有办法更改beforeInsert
和beforeUpdate
中的验证,以便isConsignment
为真,那么storeRestrictions
可以成为nullable:true
?
答案 0 :(得分:0)
我认为custom validators对您的必需品是正确的。您可以使用自定义验证程序替换存储上的nullable:true约束,该验证程序检查是寄售值
答案 1 :(得分:0)
请改为:
static constraints = {
...
storeRestrictions(validator: {field, inst ->
if( false == isConsignment)
return null != inst.storeRestrictions
)
}
了解详情