Exclusão de atributos em Lazy Fetching
26/10/2011 22:40
class User {
String userId
String password
boolean enabled
static hasMany = [ authorities: Role]
static belongsTo = Role
}
class Role {
String description
String authority
static hasMany = [people: User]
}
def role = Role.get(1)
role.people.each {
println it.userId
}
def user = User.get(1)
user.delete()
/**
* Person delete action. Before removing an existing person,
* he should be removed from those authorities which he is involved.
*/
def delete = {
def person = Person.get(params.id)
if (person) {
def authPrincipal = authenticateService.principal()
//avoid self-delete if the logged-in user is an admin
if (!(authPrincipal instanceof String) && authPrincipal.username == person.username) {
flash.message = "You can not delete yourself, please login as another admin and try again"
}
else {
//first, delete this person from People_Authorities table.
Authority.findAll().each { it.removeFromPeople(person) }
person.delete()
flash.message = "Person $params.id deleted."
}
}
else {
flash.message = "Person not found with id $params.id"
}
redirect action: list
}
grails generate-registration
Para se registrar, clique aqui.