I'm new in grails and I'm trying to delete all the objects (ArrayList) that I'm getting.
This is the method to get the data, that is working:
def authRequest = User.findAllByExpiresLessThan(currentDate)
And this is that I'm trying to do:
if(authRequest){
authRequest.delete()
}
This is the error:
Caused by: groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.delete() is applicable for argument types: () values: []
Possible solutions: sleep(long), sleep(long, groovy.lang.Closure), clear(), clear(), clear(), clone()
Thanks in advance.
authRequest.delete()
would work if it was only 1 object.
When you use findAllBy
instead of findBy
, it will return an array of objects, instead of just one. In that case you can use "Spread" operator (*.
) to delete them all:
authRequest*.delete()