waitOn
サブスクリプションのパラメーターの 1 つが、別のサブスクリプションからのドキュメントの値によって決定されるルートの部分を構成するのに問題があります。
プレイ中のコレクションは、候補者とインタビューです。面接では、候補者は 1 人だけです。サンプルデータは次のとおりです。
candidate = {
_id: 1
firstName: 'Some',
lastName: 'Developer'
//other props
};
interview = {
_id: 1,
candidateId: 1
//other props
};
ルートは次のように構成されます。
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);
};
}
});
singleCandidate
問題は、メソッドでサブスクリプションに渡す候補 ID がないことですwaitOn
。これは、インタビュー ドキュメントに保存されているためです。
考えられる解決策を 2 つ考えましたが、どちらもあまり好きではありません。1 つ目は、ルートを のように変更することです/interviews/:_id/:candidateId/conduct
。2 つ目は、データを非正規化し、候補者の情報を面接ドキュメントに保存することです。
これら2つ以外に、これを達成するための他のオプションはありますか?