CrshOverride / ember-web-api

Ember Data Addon for .NET Web API Endpoints
MIT License
20 stars 12 forks source link

Not loading relationships #11

Open pedropaf opened 8 years ago

pedropaf commented 8 years ago

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

CrshOverride commented 8 years ago

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.

LoremFooBar commented 8 years ago

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.

CrshOverride commented 8 years ago

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

LoremFooBar commented 8 years ago

@CrshOverride thanks!

vmrocha commented 7 years ago

Is this still an issue? I'm just checking if this project is still relevant? Do people use ember with Web API in production?

CrshOverride commented 7 years ago

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