Using Iron Router to waitOn subscription that's dependent on data from a doc that will come from another subscription

♀尐吖头ヾ 提交于 2019-11-28 11:12:50

You can change your publish function singleCandidate to take interviewId as paramater instead of candidateId and pass this.params._id

You may get some ideas by reading this post on reactive joins. Because you need to fetch the candidate as part of the route's data, it seems like the easiest way is just to publish both the interview and the candidate at the same time:

Meteor.publish('interviewAndCandidate', function(interviewId) {
  check(interviewId, String);

  var interviewCursor = Interviews.find(interviewId);
  var candidateId = interviewCursor.fetch()[0].candidateId;

  return [interviewCursor, Candidates.find(candidateId);];
});

However, this join is not reactive. If a different candidate gets assigned to the interview, the client will not be updated. I suspect that isn't a problem in this case though.

I had similar problem I managed to solve it via callback in subscribe

http://docs.meteor.com/#/basic/Meteor-subscribe

For example you have user data with city ids, and you need to get city objects

 waitOn: ->
    router = @
    [
        Meteor.subscribe("currentUserData", () ->
          user = Meteor.user()
          return unless user
          cityIds = user.cityIds
          router.wait( Meteor.subscribe("cities", cityIds)) if cityIds        
        )
    ]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!