Skip to content

Instantly share code, notes, and snippets.

@neodevelop
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neodevelop/54953d90cc778b71548a to your computer and use it in GitHub Desktop.
Save neodevelop/54953d90cc778b71548a to your computer and use it in GitHub Desktop.
Batch delete in #grails
groupsToDelete = []
Group.list().each { group ->
if(group.members.isEmpty())
groupsToDelete << link
}
groupsToDelete*.delete()
Group.where {
members.size() == 0
}.deleteAll()
import grails.gorm.*
def criteria = new DetachedCriteria(Group).build {
isEmpty 'members'
}
criteria.deleteAll()
// criteria.count()
class Group {
String name
static hasMany = [members : Member]
}
class Member {
String name
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment