Search code examples
spring-mvcgrailsgroovygrails-ormgrails-2.0

Grails validate delete() Operation?


When deleting an instance with Grails I can perform

def user = User.get(1)
user.delete(flush: true)

For an instance I can validate if a save operation will succeed:

user.validate()

Is it possible to validate if a delete() will be successful before doing delete?


Solution

  • I don't think there's a way to 'dry run' a delete in Grails. You could do something like this though:

    try{
       user.delete(failOnError:true)
    } 
    catch(e) {
       //it didn't work, do something about it here
    }