0
votes

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))
  }
}

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

2

2 Answers

2
votes

You will have to use Grails custom validation using the validator

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

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