Meteor.publishComposite('allPostsWithComments', {
find: function(){
return Posts.find({"status.deleted": false}, POST_OPTIONS);
},
children: [
{
// find related post owner
find: function(post, activity){
return Meteor.users.find({_id: post.user_id }, USER_OPTIONS );
},
},
{
// find related post comments
find: function(post, activity){
return Comments.find( { post_id: post._id, "status.deleted": false } );
}
},
]
});
Meteor.publishComposite('onePost', function(postId) {
return {
find: function() {
// Find posts made by user. Note arguments for callback function
// being used in query.
return Posts.find({ _id: postId }, POST_OPTIONS);
},
children: [
{
find: function(post){
// publish post owner
return Meteor.users.find({_id: post.user_id}, USER_OPTIONS);
},
},
{
find: function(post){
// publish post comments
return Comments.find({post_id: post._id, "status.deleted": false});
},
children: [
{
find: function(comment, post){
// publish users related to comments
return Meteor.users.find({_id: comment.user_id}, USER_OPTIONS);
}
}
]
}
]
}
});
this.route('explore', {
waitOn: function () {
// return one handle, a function, or an array
return [
subsManager.subscribe('allPostsWithComments'),
];
},
});
this.route('postShow', {
path: '/post/:_id',
waitOn: function () {
return [
subsManager.subscribe('onePost', this.params._id),
];
},
data: function () {
return { post: Posts.findOne({_id: this.params._id}) };
},
yieldRegions: {
'_postOptions': {to: 'options'},
'_headerBack': {to: 'header'},
'_newCommentFooter': {to: 'footer'},
},
});
As you can see in this scenario in "onePost" publication I'm not filtering posts by "status.deleted: false". That's because I want to publish deleted post only to "postShow" route and if it's deleted, I'm showing manual message to user: "This post has been deleted".
But I do filter by "status.deleted: false" on "explore" page as you can see in "allPostsWithComments" publish.