-
Notifications
You must be signed in to change notification settings - Fork 80
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
Empty one-to-one relationship incorrectly surfaced (should be surfaced as null) #277
Comments
upstream bug beam-community#277, which is logged at beam-community#277
upstream bug beam-community#277, which is logged at beam-community#277
I've created a PR to workaround (maybe even solve or partially solve?) this issue at #278 I've annotated the code at https://github.com/beam-community/jsonapi/pull/278/files for a clearer explanation. The key moment in the code is here where we can cleanly surface a nil without many code changes. |
Outstanding WorkIf this approach bears fruit then we need to
|
My reading of the JSON:API specification has always left this as an implementation detail. In my reading, a relationships object (plural) must contain keys which are each valid relationship objects but it is not required to contain the same keys for every request for a certain resource. Therefore, a to-one relation that does not exist (may be In my opinion, it is nonetheless unfortunate for a library to pick one or the other because I actually feel there's a useful distinction between omitting and nulling out in an API contract and both should be possible depending on the API. At any rate, I would call this a feature request more than a bug based on my understanding of the specification. |
Hi @mattpolzin, thanks for the quick reply. I haven't internalised the JSON:API specification in detail in this area - your reading of it sounds reasonable to me and I am happy to yield to that interpretation :-) I agree that supporting both would be ideal if that is what the spec allows. So I'd be in agreement with your above suggestions. |
Currently, if there is a one-to-one relationship and it is empty the related resources key gets removed from the "relationships" object. But, according to https://jsonapi.org/format/#document-resource-object-linkage this should not happen...
"Resource linkage MUST be represented as [...] null for empty to-one relationships."
Rather, the relationship data should be set to null - there is an example at https://stackoverflow.com/a/57414080
Here is an example...
Expected Result
If author is null, we should get...
Actual Result
But if author is null, we actually get...
No author relationship.
The text was updated successfully, but these errors were encountered: