I am trying make use of the nested URL as documented in the RestFul URLs section
It seems that the nested resource is not receiving a reference to the object the url is deriving from. URLmapping:
"/books"(resources: 'book') {
"/reviews"(resources: "review")
}
...
@Resource(uri = '/books', formats = ['json', 'xml'])
class Book{
static hasMany = [reviews: Review]
}
...
@Resource(uri = '/reviews', formats = ['json', 'xml'])
class Review{
static belongsTo = [book: Book]
...
static constraints = {
book nullable: false
}
}
The error is a 422 pointing to
Grails default.null.message
{
"message": "Die Eigenschaft [book] des Typs [class core.Review] darf nicht null sein",
...
}
}
Is this a bug!? If not, how to properly make use of Nested URLs for Rest Resources in Grails (tested: Grails 4.0.3)
Update: Request is being sent to:
POST $domain/books/1/reviews
{
"description":"amazing book"
}
adding a "book":1
in JSOn will create the review just fine. But that is not the point of using nested URL isn't it?