I'm having trouble configuring the waitOn
portion of a route where one of the subscription's parameters is determined by the value from a doc that comes from a different subscription.
The collections in play are Candidates and Interviews. An interview will have one and only one candidate. Here's some sample data:
candidate = {
_id: 1
firstName: 'Some',
lastName: 'Developer'
//other props
};
interview = {
_id: 1,
candidateId: 1
//other props
};
The route is configured as follows.
this.route('conductInterview', {
path: '/interviews/:_id/conduct', //:_id is the interviewId
waitOn: function () {
return [
Meteor.subscribe('allUsers'),
Meteor.subscribe('singleInterview', this.params._id),
// don't know the candidateId to lookup because it's stored
// in the interview doc
Meteor.subscribe('singleCandidate', ???),
Meteor.subscribe('questions'),
Meteor.subscribe('allUsers')
];
},
data: function () {
var interview = Interviews.findOne(this.params._id);
return {
interview: interview,
candidate: Candidates.findOne(interview.candidateId);
};
}
});
The problem is that I don't have a candidateId to pass to the singleCandidate
subscription in the waitOn
method because it's stored in the interview doc.
I've thought of two possible solutions, but I don't really like either of them. The first is to change the route to something like /interviews/:_id/:candidateId/conduct
. The second is to denormalize the data and store the candidate's info in the interview doc.
Are there any other options to accomplish this besides those two?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…