grailsgroovygrails-domain-classgrails-validation

date range validation groovy grails


I am new to groovy grails so any help would be appreciated. I am working on a grails application which tracks employee workplace history. One of the validation requirements is that the start date and end date duration for an employee should not overlap. That means the startDate..endDate range should be unique among his employment dates for every employee. So my question is that how should I handle this validation ? Should it be done in the static constraint block as a custom validator or it should be done in database level?


Solution

  • While your implementation of this is probably dependent on your specific needs, there is no absolutely correct answer on how you should do this. There are good reasons for one or the other though:

    From my perspective, I'd implement the validator in the application only, then have a way for handling invalid data if it's loaded from elsewhere. If data validity is paramount, then I'd probably implement the validator in both places, being 100% sure that the logic matches!