ember-web-api icon indicating copy to clipboard operation
ember-web-api copied to clipboard

Not loading relationships

Open pedropaf opened this issue 9 years ago • 6 comments

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

pedropaf avatar Aug 03 '16 10:08 pedropaf

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.

CrshOverride avatar Sep 12 '16 01:09 CrshOverride

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.

LoremFooBar avatar Sep 19 '16 07:09 LoremFooBar

@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 avatar Sep 19 '16 19:09 CrshOverride

@CrshOverride thanks!

LoremFooBar avatar Sep 19 '16 19:09 LoremFooBar

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 avatar Jan 11 '17 12:01 vmrocha

@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.

CrshOverride avatar Jan 16 '17 17:01 CrshOverride