1

I'm struggling with the following: So i got a list of ids in a user object, i would like to retrieve the list of users, whose those ids belong to. My idea was to use a map to convert the array of ids to an array of users, I came to the obvious wall. since the call is asynchronous y can't expect the users to be there, however yes the promise. Is there anyway to return this promises in a way that Ember can show the data when they get resolved ? I don't really care when they get resolved. but when they do, that they render the data. What is happening now is that i get a list of Promises, which is fine, and kind of expected, but how do i tell ember, ok when you do resolve the promises show the data?

Thanks in advance

let users = this.get('user.followingIds').map((followerId) => {
    return this.store.findRecord('user', followerId).then((user) => {
        console.log('resolved follower ', user.get('name'));
        return user;
    }).catch((e) => {
        console.error('user catch', e);
    });
});

this.set('followers', users);

The console log output is

resolved follower  james stuart

on onother filter i have this

this.store.query('followers', {}).then((followers) => {
    this.set('followers', followers);
}).catch((e) => {
    console.error('publisher catch', e);
});

and that works as expected, but its not in a map, this is just to show im displaying the results the right way

GJK
  • 37,023
  • 8
  • 55
  • 74
jstuartmilne
  • 4,398
  • 1
  • 20
  • 30
  • Can you include `console.log` of `users` value after calling `.map` and `console.log` of `resolvedUsers` from my answer? – Daniel Kmak Nov 04 '15 at 14:49
  • your resolvedUsers do get printed. but its not shown, i cant understand why, im setting the followers in the same way as the other filter – jstuartmilne Nov 04 '15 at 15:09
  • I do get this warning when clicking on that filter : DEPRECATION: The default behavior of `shouldBackgroundReloadRecord` will change in Ember Data 2.0 to – jstuartmilne Nov 04 '15 at 15:14
  • I just want to know if `users` is non-empty array with promises before passed to `RSVP.all` and what's the `resolvedUsers`. If you get any warning it'd be helpful if you could post its contents here. – Daniel Kmak Nov 04 '15 at 15:15
  • Ok, this warning isn't associated. – Daniel Kmak Nov 04 '15 at 15:17
  • the array is a non empty array, and i was able to console.log the users from the then block, in the answer you provided. (not sure why you deleted, i think we are on the right track) however for some reason i get that warning and not the users printed – jstuartmilne Nov 04 '15 at 15:29

1 Answers1

1

Thank u Daniel for the help, i ended up changing the map for a forEach and populating the array

this.get('user.following').forEach((followerId)=>

        {
             this.store.findRecord('user', followerId)
                .then((user) => {
                    console.log('resolved follower ',user.get('name'));

                                                publishers.pushObject(user._internalModel);

                })
                .catch((e) => {
                    console.error('publisher catch', e);
                });

        });

I had to put the _internalObject thing otherways it wouldn't work took that from here Dynamically add js object to model array in 1.13

Community
  • 1
  • 1
jstuartmilne
  • 4,398
  • 1
  • 20
  • 30