I have a domain class that must have a date after the day of creation in one of its fields.
class myClass { Date startDate String iAmGonnaChangeThisInSeveralDays static constraints = { iAmGonnaChangeThisInSeveralDays(nullable:true) startDate(validator:{ def now = new Date() def roundedDay = DateUtils.round(now, Calendar.DATE) def checkAgainst if(roundedDay>now){ Calendar cal = Calendar.getInstance(); cal.setTime(roundedDay); cal.add(Calendar.DAY_OF_YEAR, -1);
So, a few days later, when I change only the line and the call, the save fails because the validator is double-checking the date, and now it is in the past. Can I make sure that the validator only starts when it is created, or somehow I can change it to determine if we are creating or editing / updating?
@Rob H I'm not quite sure how to use your answer. I have the following code causing this error:
myInstance.iAmGonnaChangeThisInSeveralDays = "nachos" myInstance.save() if(myInstance.hasErrors()){ println "This keeps happening because of the stupid date problem" }
Mikey source share