I'm using the Grails 3 grails.rest.Resource annotation in the following way:
@Resource(uri='/parent')
class Parent {
static hasMany = [children: Child]
}
class Child {
String property1
String property2
static belongsTo = [parent: Parent]
}
Now, let's say, I have a Parent object with 2 children and I issue a GET request for that Parent with something like GET localhost:8080/parent/1
. The JSON response will look something like (assuming I'm not using the default JSON renderer, but that may not actually be relevant):
{
"id": "1",
"children": [
{
"id": "1",
"property1": "prop1",
"property2": "prop2"
},
{
"id": "2",
"property1": "prop1",
"property2": "prop2"
}
]
}
I want to be able to issue a PUT request with a JSON payload that looks something like...
{
"id": "1",
"children": []
}
... and have all of the children of the Parent be deleted.
Is this possible without implementing a custom rest controller? The children in this case are dependent objects and ideally this would be a single update as opposed to issuing separate DELETE requests on a rest controller for Child objects, and it would also be nice to not have to implement custom code to do the child delete =D.