I have a situation which is best described using the following code:
Meteor.publish('users', function (name) {
return Users.find({name: name});
});
Meteor.publish('posts', function (userId) {
return Posts.find({userId: userId}, {sort: {insertDate: 1}});
});
A user has many posts. So, when the url is
http://example.com/john
So, to find the posts for a specific user I need to know the id of the user.
Now I have the following Controller:
UserController = RouteController.extend({
onBeforeAction: function () {},
waitOn: function () {
var userSub = Meteor.subscribe('user', this.params.name);
return [userSub];
},
data: function () { ... },
action: function () {
if (this.ready()) {
this.render('user');
}
else {
;//this.render('loading');
}
}
});
Now I can only waitOn
the user, but I also want to waitOn the Posts, but how can I do this, because to subscribe to the posts I need to know the userId:
Meteor.subscribe('posts', user._id);
Any suggestions ?