Proper way to use 2 helpers eachother

I’ve got one helper which has data from my collection Food:

// helper
food() {
        return Food.find({}, {
          sort : this.getReactively('sort')
        });
      }

And I’ve got a ng-repeat in my view to show this data. One of the fields is owner which is the user’s id.
I’ve got another function to get the user avatar with the id (but I’m not sure if the correct way would be a function or another helper):

// function
getAvatar(id) {
    console.log(id);
    var query = Meteor.users.findOne(id, {fields: {avatar: 1} });
    return query.avatar;
  }

In ng-repeat:

<div class="plate-name">{{plate.name}}</div>
<div class="user-avatar">{{foodList.getAvatar(plate.owner)}}</div>

Is this the correct way? The result is ok but the console.log is called more than 100 times! with 6 images. So, I understand something is not ok despite of all (I’ve removed the sort and is not that).

You could try to map the foods in the first helper to the avatars

// helper
food() {
        return Food.find({}, {
          sort : this.getReactively('sort')
        }).fetch().map(food => {
              const owner = Meteor.users.findOne(food.owner, {fields: {avatar: 1} });
              food.avatar = owner && owner.avatar;
             return food;
        });
      }

1 Like

Thanks @jorgeer, this really helped me :wink:
Exactly what I was looking for