Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch, Post resource relationships on non owner field #784

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jbmolle
Copy link
Contributor

@jbmolle jbmolle commented Sep 7, 2020

Hi,

Currently it's not possible to Patch/Post a resource with a mappedBy relationship (where the field is not the owner of the relationship).
So that may be a problem because someone using the API may not have information on which relationship field is owner and which relationship field is owned.
This PR is a first attempt to solve that. It is a rework of #697

Best,
JB

@remmeier
Copy link
Contributor

it goes a bit into a dangerous area. JSON:API/restful services have a rather strong semantic of resources and a single repositry being responsible for a resource. An update should touch it accordingly. This is reflected by the ownership. By allowing to update it from the opposite non-owning side, updates become much much more complex and can involve many repositories.

there are alternatives (orthogonal concerns, can also be combined).

  • updating on the owner-side with multiple calls
  • doing bulk/operations requests (there seems also progress on the JSON:APi spec side about this matter).
  • make use of the relationship endpoints

@jbmolle
Copy link
Contributor Author

jbmolle commented Sep 21, 2020

Hi @remmeier
Thanks for your feedback!
I understand your point. I could use the relationship endpoints but I thought it would be easier to update directly the document relationships with a PATCH request.
I think it follows the JSON:API spec version 1.1 under "Updating a Resource’s Relationships" paragraph. Any or all of a resource’s relationships MAY be included in the resource object included in a PATCH request. It doesn't talk about ownership in the paragraph.
The pull request doesn't try to update the attributes of the relationship.
So if you have companies and joboffers with companies having many joboffers and a joboffer belonging to one company. You should be able to update the company relationship { id: xxxx, type: "companies" } on the joboffer as well as update the joboffers relationship [ { id: xxx, type: "joboffers" } ] on the company.

But you're right, we can also use the relationship endpoints and I think the bulk/operations requests spec that's coming will also be very useful.

Thanks,
JB

@remmeier
Copy link
Contributor

I entirely see the point. Maybe it would be good to have it as add-on for a start. or to have an annotation on the relationship to allow this kind of propagation (similar to JPA allows to specify propagation behavior). But the default behavior should be simple I think, meaning only touching one repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants