-
Notifications
You must be signed in to change notification settings - Fork 24
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
Links-only relations not handled correctly #77
Comments
@lindyhopchris, can you verify this is fixed on master? |
@JaZo Hi! thanks for looking at this so quickly. This does now work - it doesn't assume that a links-only relation is empty. However, it throws up a new issue when saving the resource. Relations with no
And for updating...
In other words, the serialization for an outbound request from the client to the remote server is a bit different - it needs to strip out relations that do not have a |
You are absolutely right, missed that! I've changed the serialization to strip out relations without a |
Fix released in 1.1.1. |
Detailed description
If you retrieve an item that has links-only relations, modify it and then save it - the JSON sent to the remote server includes the relations with an empty
data
member - even though the client doesn't know what thedata
content of that relationship is.Here's an example to illustrate this. Given this code:
Say the server replied to the find request with this:
I.e. the comments relationship has no
data
member.When
toJsonApiArray()
is called, it will serialize this:I.e. the comments relationship now has an empty
data
member. This is incorrect because thedata
member was never retrieved from the remote server, so the client has no way of knowing what the value for the relationship is.Presumably the same bug will occur if the server replied with a relationship that only had a
meta
member.Context
The JSON API spec says that a relationship must have at least one of
data
,links
,meta
- so the client should handle relationships that do not have thedata
member. It should not assume the relationship has an emptydata
member for a relationship for which it has not been provided a data member.In my scenario, changing an attribute on the post and saving it back to the server causes the request to be rejected, as the server does not accept a
data
member for the comments relationship.Possible implementation
When serializing relationships, particularly when saving the resource, any relationships that do not have a
data
member should be skipped, rather than the relationship being assumed to be empty.Your environment
Laravel 7.22, PHP 7.2, latest version of this package.
The text was updated successfully, but these errors were encountered: