开发者

Grails validation dependent on other attributes

What is the correct way to do something like this with grails:

class myDomainThing {
  String description
  MyOtherDomainThing otherThing

  static constraints = {
    description(nullable:if(otherThing))
    otherThing(nullable:if(description))
  }
开发者_JS百科}

So I either want there to be a link to the otherDomainThing or I want a String description.


You will have to use Grails custom validation using the validator

static constraints = {
  description(validator: {
        return otherThing and !description
    })
}


you'll need to use a custom validator

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

obviously some pseudocode in there around otherthing

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜