mardi 13 mars 2018

Ember model hook with a Promise.All and several findAll()

I thought I understood how the store.findAll and the Promise.All works. But I have run into some strange behavior. I have two findAll(), but only one of them is fullfilled after the Promise.All gets into the then()-part.

See this code

export default Route.extend({
model() {
    var self = this;
    return Ember.RSVP.Promise.all([
        self.store.findAll('contact'),
        self.store.findAll('message')
    ]).then(function(values) {
        var contacts = values[0];
        var messages = values[1];
        var numberOfContacts = contacts.get('length');  // This is 39 as expected.
        var numberOfMessages = messages.get('length');  // This is 0. Expected is 1. 
        ...

There must be something different with messages and contacts, but I cannot figure out what it is. They have very similar models and they have very similar backend API handling. From the network traffic I can see that a message object is returned and if I call (later in the code, after the model hook):

store.peekAll('message');

I get the message object I expect.

I use ember 3.0.0




Aucun commentaire:

Enregistrer un commentaire