Closed kamal closed 4 years ago
this is looks like a bug on server side if relationship has data corresponding object must be included in payload @kamal do you have real life case with such behaviour?
@senid231 by reading the spec and based on interactions with other clients (ember-data) --- it doesn't seem like you must include a resource in the payload if you are using a resource linkage in the relationships data.
From https://jsonapi.org/format/#document-compound-documents
Resource linkage in a compound document allows a client to link together all of the included resource objects without having to GET any URLs via links.
The behavior I've seen is: if there is a linkage and the resources in included
then user it, otherwise GET
it.
However, if you include a resource in included, then it must have a linkage:
In a compound document, all included resources MUST be represented as an array of resource objects in a top-level included member -
@abuiles I get your point. Indeed I can't find in spec requirement that object must be present in included or dataset if it's id and type are present in relationships. I've always used it as de facto rule
Given a payload that looks something like
where the relationship has
data
, but whose full data does not appear inincluded
, the current code will raise an exceptionundefined method '[]' for nil:NilClass
.This PR changes how the included data is accessed that avoids this exception, by using
Hash#dig
. It then falls back to fetching the relationship via a request.