spring-projects / spring-projects/spring-data-rest
Posting to a nested collection resource does not work as expected [DATAREST-608]
@odrotbohm is already working on this.
Since Dec 31, 2020.
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
Chris Beams opened DATAREST-608 and commented
Given entities Person and Posession, where Person has a collection of Possessions and both entities are exposed via SD REST repositories respectively, I would expect to be able to do something like the following:
POST /person/1/posessions
{ "name": "car" }
However, such a POST returns 405 or 204 depending on the context in which I call it (haven't debugged this fully).
It does of course work to post the new possession directly against its root collection resource:
POST /posessions
{ "name": "car", "person": "/person/1" }
I don't see anything in the documentation stating that mutative operations on nested collection resources are (or are not) supported. Am I missing something?
Note that it does seem like this use case is intended to be supported, based on tracing my way through RepositoryPropertyReferenceController#createPropertyReference (which does get called in the cases where the request does not immediately return 405). What I don't understand here is why this method calls #doWithReferencedProperty but then always returns 204 even for POSTs.
Affects: 2.4 M1 (Gosling)
3 votes, 4 watchers
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.