Last active
August 29, 2015 14:20
-
-
Save neodevelop/54953d90cc778b71548a to your computer and use it in GitHub Desktop.
Batch delete in #grails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
groupsToDelete = [] | |
Group.list().each { group -> | |
if(group.members.isEmpty()) | |
groupsToDelete << link | |
} | |
groupsToDelete*.delete() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Group.where { | |
members.size() == 0 | |
}.deleteAll() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import grails.gorm.* | |
def criteria = new DetachedCriteria(Group).build { | |
isEmpty 'members' | |
} | |
criteria.deleteAll() | |
// criteria.count() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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