Grails class domain validator, the property must be larger than another property

I have the following domain class in my grails project:

class Vacation { Date start Date end User vacationer static constraints = { start(validator: {return (it >= new Date()-1)}) } } 

Is it possible to add a validator that requires the end to be equal to or greater than the start?

Greetings

+4
source share
2 answers

Using

 start(validator: { val, obj -> val < obj.properties['end'] }) 
+7
source

You can directly access the end property, since the obj object is an object of the Vacation class only if it is defined. Using:

start (validator: {val, obj โ†’ val <obj.end})

+1
source

All Articles