views:

553

answers:

2

Hi folks,

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 end to be equal or greater than start?

Cheers

+1  A: 

Use

start(validator: { 
   val, obj ->
      val < obj.properties['end']
})
Robert Munteanu
Works perfect. Thanks.
Error Prone
A: 

You can directly access property "end", since obj is the object of the class Vacation only, where it is defined. Use:

start(validator: { val, obj -> val < obj.end })

Amit Jain