2011-05-06 58 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