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

Empty belongsTo relationship not passed back in correct JSONAPI format #519

Closed
nickschot opened this issue Nov 11, 2016 · 1 comment
Closed
Assignees
Labels

Comments

@nickschot
Copy link
Contributor

nickschot commented Nov 11, 2016

Currently an empty belongsTo relationship looks like this in the server response:

...
relationships: {
    user: null
}
...

While JSON API states the following format must be followed:

...
relationships: {
    user: {
        data: null
    }
}
...

The only difference with hasMany relationships is that those must (and do) have a data: [] instead of data: null.

Relevant literature: http://jsonapi.org/format/#document-resource-object-relationships
It also states there that a relationship response must contain at least one of data, links or meta.

I have not checked if the server handles this correctly when sending a request.

@nickschot
Copy link
Contributor Author

nickschot commented Nov 11, 2016

Culprit seems to be in packages/serializer/index.js from line 628. The else if(related && related.id) fails when related is null and it then just returns null. I guess the format is also wrong when a belongsTo relationship is found as no {data: ...} is present within the else if either.

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

No branches or pull requests

2 participants