jeudi 23 février 2017

Ember Data won't load related models from API

I have a model with several related models. I'm trying to call in my route return this.store.findAll('my-model'), which gets JSON data from the API. It returns attributes, which I can access fine, and has the related model names in relationships, and the models also appear in the included section. However, the related models are not being populated into the Ember store, unless I make a separate findAll request for them.

In Ember Inspector I can see 'my-model', and the list of relationships appears, but for the related model all that appears is <(subclass of Ember.ObjectProxy)>, which I believe is a promise object. However, the promise is coming up as fulfilled.

It was my understanding that Ember is supposed to get related models automatically along as their relationships are defined. If I have a model 'my-model' with a property 'property', and a related model 'related-model' with a property 'related-property', I thought I should be able to do 'myModel.property', and 'myModel.relatedModel.relatedProperty', but only the first item works.

I've tried the advice in Couldn't access related models in ember.js 2.0 using ember-data but no joy. And much of the previous seemingly relevant questions on here are too old to be of use as Ember changes so much. I cannot seem to get the models to relate to each other. I've tried loading each model separately in the route, I've tried an RSVP hash, I've tried .then(), nothing works. Is there something extra I have to do to handle an API, or is there something I'm missing? How can I access the related models?




Aucun commentaire:

Enregistrer un commentaire