Monday, July 31, 2017

Saving a GORM object

try {
    if (!term.save(flush: true)) {
        term.errors.allErrors.each {
            print it
        }
        flash << [success: false, message: 'Errors while changing term', obj: term]
        return    } else {
        def oldTerms = Term.findAll()
        oldTerms = oldTerms.remove(Term.findIndexOf {term})
        oldTerms.each { oldterm ->
            oldterm.active = false            oldterm.save(flush: true)
        }
        flash << [success: true, message: 'Updated term successfully!']
    }
}
catch (org.springframework.dao.DataIntegrityViolationException e) {
    flash << [success: false, message: 'Attempted duplicate term', obj: term]
    return false}

No comments:

Post a Comment