Not loading relationships
Hi, I'm using this adapter for an ember-cli 2.6 app. And I'm using .NET Web API.
I have 2 models:
Team:
export default Model.extend(Validations, {
name: attr(),
teamLeader: belongsTo('user', { inverse: null }),
users: hasMany('user'),
});
User:
export default Model.extend({
firstName: attr(),
lastName: attr(),
team: belongsTo('team', { inverse: 'users' })
});
On my index route, I request to get all teams, and I have this response from the API:
[
{
"id": 1,
"name": "Inbound",
"teamLeader": 9000,
"users": []
},
{
"id": 4,
"name": "Energy Renewals",
"teamLeader": 9000,
"users": []
}
]
I can render the list of teams, but there's no request to the API to get the TeamLeader details. So if I try to render the name of the TeamLeader, it's always empty. I'm following all Ember Data and Ember Rest Adapter documentation and I can't find anything wrong. Any ideas?
Thanks
It looks like you forgot to set the { async: true } option on your belongsTo relationship. Give that a shot and see if the request gets sent.
Hi, the same thing happens to me as well with async: true. I noticed that sideloadItem function in the serializer assumes that the data in the relationship key is an object (or an array of objects), and doesn't make a request to get the record by ID.
@lazyboy1 When I originally wrote this, it was for a specific use-case where all of our data was nested in the initial response. I'll take a look later today and see if there's an easy fix for this. Thanks for the feedback!
@CrshOverride thanks!
Is this still an issue? I'm just checking if this project is still relevant? Do people use ember with Web API in production?
@vmrocha This project is definitely still relevant. Several teams are using it production but haven't hit this issue. Unfortunately I've been busy with upgrading a few of our projects to Ember 2.10 and haven't had time to circle around and look into this again.