Im able to show list of posts of a specific user but not able to show posts that contains comments by a specific user.
The example in the official links uses this hierarchy here
For my problem, the hierarchy is:
all posts ->
(children)
-> find all post by user
-> find all comment by user
(children)
-> find post that has id that matches comments
What I have so far..
Publish Composite lines
Meteor.publishComposite('user', function(_id) {
return {
find: function() {
return Meteor.users.find({_id: _id}, { fields: { profile: 1, username: 1} });
},
children: [
{
find: function(user) { return Posts.find({ userId: user._id }); }
},
{
find: function(user) { return Comments.find({ _id: user._id }); }
children: [
{
find: function(comment) { return Posts.find({ _id: comment.postId }); }
}
]
}
]
};
});
In the template
Template.usersShow.helpers({
user: function () {
return Meteor.users.findOne({ _id: Router.current().params._id });
}
});
In the router
Router.route('/users/:_id', { name: 'users.show',
waitOn:function(){
// console.log(this.params._id);
return Meteor.subscribe('user', this.params._id);
}
});
html
{{#with user}}
<div class>{{ profile.name }}</div> <!-- name appears -->
{{#ionList}}
{{#each post}}
{{> postItem}}
{{/each}}
{{/ionList}}
{{/with}}