2011-05-06 49 views
0

什麼是做這樣的事情在Grails正確的方法:Grails的驗證依賴於其他屬性

class myDomainThing { 
    String description 
    MyOtherDomainThing otherThing 

    static constraints = { 
    description(nullable:if(otherThing)) 
    otherThing(nullable:if(description)) 
    } 
} 

所以我要麼希望這是給otherDomainThing鏈接或我想要一個字符串描述。

回答

2

你將不得不使用 validator

static constraints = { 
    description(validator: { 
     return otherThing and !description 
    }) 
} 
使用Grails的自定義驗證
0

你需要使用一個自定義的驗證

static constraints = { 
    description validator: { val, obj -> 
    if(otherthing && val) { 
     false 
    } 
    else { 
     true 
    } 
    } 
} 

顯然有些僞代碼中有沒有解決otherthing