vendredi 27 janvier 2017

Ember store not loading nested hasMany relationship data

I am making a call to an API I built. The response returns a big JSON with all the data nested within it (meaning no need to asynchronously make separate calls for nested related models).

Example:

"feed" : {
  "id": 12345,
  "name": "trogdor",
  "items": [
    {
      "id":6789,
      "content": I am an items content
    },
    {
      "id":6789,
      "content": I am an items content
    },
    {
      "id":6789,
      "content": I am an items content
    },
    {
      "id":6789,
      "content": I am an items content
    }
  ]
}

So as you can see, the Feed model which is return hasMany items.

So my models are defined as such:

Feed Model:

export default DS.Model.extend({
  name: attr('string'),
  items: hasMany('item')
});

Item Model:

export default DS.Model.extend({
  content: attr('string'),
  items: belongsTo('feed')
});

But when the promise is return from my model call, no data is set when I call for the model's "items". Instead I just get a store class with no attributes or data.




Aucun commentaire:

Enregistrer un commentaire