Skip to content

Null sideloaded relationships including links #248

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

Closed
jaredcnance opened this issue Apr 2, 2018 · 4 comments
Closed

Null sideloaded relationships including links #248

jaredcnance opened this issue Apr 2, 2018 · 4 comments

Comments

@jaredcnance
Copy link
Contributor

jaredcnance commented Apr 2, 2018

if User.Profile == null we will still return the profile link

/users?include=profile

{
  "relationships": {
    "profile": {
      "links": {
        "self": "/users/1/profile"
      }
    }
  }
}
@jaredcnance
Copy link
Contributor Author

After discussing with dgeb, more research needs to be done to ensure this is not a client issue.

this is a problem with Ember Data imo
I’m strongly against implicit fetches ever being triggered
it’s fine (and proper) to return the self link regardless of whether data is also returned

@FabHof
Copy link

FabHof commented Jan 22, 2019

Wouldn't it make sense to add "data": null to indicate, that there is no profile? That's also how I read the spec: https://jsonapi.org/format/#document-resource-object-linkage AND https://jsonapi.org/format/#fetching-relationships

If the above relationship is empty, then a GET request to the same URL would return:

HTTP/1.1 200 OK
Content-Type: application/vnd.api+json

{
  "links": {
    "self": "/articles/1/relationships/author",
    "related": "/articles/1/author"
  },
  "data": null
}

Just adding a self link gives no information about if there is a profile or not.

Is there an easy way to add "data": null?

@RKennedy9064
Copy link

@jaredcnance I'm also experiencing this issue, so I figured I would add to the open issue. I'm also using Ember Data and have relationships that can sometimes be null. When one of my relationships is null, the returned data looks like this:

/staff-roster?include=region

"relationships": {
    "region": {  
        "links": {  
            "related": "/api/v1/staff-roster/21/region"  
            "self": "/api/v1/staff-roster/21/relationships/region"  
        }  
    }  
}  

Since I'm displaying information in a paginated table, whenever the relationship is null and only the links are included, Ember will make a get request for every row which just returns:

{
    "data": null
}

I'm hoping to avoid having the front end do a get request for every relationship that's null and returns a link with no data. I'm not sure if it should be handled here in the back end, or if it should be handled with Ember Data, so I figured I would share my information regarding this issue as well. Is there an easy way to add "data": null in the meantime?

@maurei
Copy link
Member

maurei commented Oct 10, 2019

This has been fixed in the new serialization layer. See #558. Specifically, see the ResponseResourceObjectBuilder thats that cover this functionality

@maurei maurei closed this as completed Oct 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants