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

ToOne and ToMany should allow for having just one of data, links or meta fields #2

Closed
yaviso opened this issue Apr 1, 2021 · 3 comments

Comments

@yaviso
Copy link

yaviso commented Apr 1, 2021

Per the spec:

A “relationship object” MUST contain at least one of the following:

  • links: a links object containing at least one of the following:
    • self: a link for the relationship itself (a “relationship link”). This link allows the client to directly manipulate the relationship. > For example, removing an author through an article’s relationship URL would disconnect the person from the article without deleting the people resource itself. When fetched successfully, this link returns the linkage for the related resources as its primary data. (See Fetching Relationships.)
    • related: a related resource link
  • data: resource linkage
  • meta: a meta object that contains non-standard meta-information about the relationship.
@lindyhopchris
Copy link
Contributor

"at least one of the following" does mean that it can have just one of data, links and meta.

yaviso added a commit to yaviso/spec that referenced this issue Apr 1, 2021
fix: ToOne forces `data`

Fixes laravel-json-api#2
@yaviso yaviso mentioned this issue Apr 1, 2021
@lindyhopchris
Copy link
Contributor

I must apologise - I completely misread this issue when you opened it! I hadn't taken in it was in the laravel-json-api/spec repo.

So the part of the spec that is relevant here says this:

[When creating a resource] If a relationship is provided in the relationships member of the resource object, its value MUST be a relationship object with a data member. The value of this key represents the linkage the new resource is to have.
https://jsonapi.org/format/#crud-creating

And for updating:

If a relationship is provided in the relationships member of a resource object in a PATCH request, its value MUST be a relationship object with a data member. The relationship’s value will be replaced with the value specified in this member.
https://jsonapi.org/format/#crud-updating

The section you've quoted is about the serialization of a relationship within a resource object, i.e. when a server is serializing a resource.

@yaviso
Copy link
Author

yaviso commented Apr 3, 2021

I'm sorry, you are complete correct... Guess now I'll have to see how I get my client lib to not serialize relationships for PATCH/POST when there is no data available (but links is)...

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 a pull request may close this issue.

2 participants