Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4838

JSON Api Included Relationship Issue

$
0
0

@rkennedy9064 wrote:

I’ve been using Ember to interact with a JSON Api project and seem to have run into an issue. I’m displaying related data that’s been included using a normal include query like this:

/staff-roster?include=region

The issue I’m running into is that since some of my relationships can be null, and since JSON Api only needs to include links, data, and/or meta, my responses with null relationships look like this.

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

Then when I access the relationship to be displayed in my table using staffRoster.region.label, Ember thinks the relationship hasn’t been loaded yet and sends a get request for every row in the table where region is null since no data element is included in the results. I’ve also tried switching over to a sync relationship with ‘region’: belongsTo(‘region’, { async: false }), but any row that contains a null region gives me this warning message in the console:

WARNING: You pushed a record of type 'staff-roster' with a relationship 'region' configured 
as 'async: false'. You've included a link but no primary data, this may be an error in your 
payload. EmberData will treat this relationship as known-to-be-empty.

It technically works when I use async: false since I’m including the related data, but I don’t like how it generates hundreds of those warnings as I grab each new page. Is there a better way to tell Ember to not fetch relationships that are null, or a proper way to handle async: false relationships where the relationship can be null so I don’t get that warning? Any help would be greatly appreciated.

Posts: 5

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 4838