Reputation: 317
In my server folder I have a file where i'm doing the following
Meteor.publish("all_jobs", function(jobs) {
return Jobs.find();
});
Meteor.publish("user_jobs", function(user_id) {
return Jobs.find({userid: user_id}, {sort: {date: -1}});
});
On the user his blogpost page I do the following:
Session.set("userid", Meteor.userId());
Meteor.subscribe("user_jobs", Session.get("userid"));
Template.userJobs.helpers({
jobs: function(){
return Jobs.find();
}
});
On my homepage I would need all the blogpost. So i'm trying to access Meteor.subscribe("all_jobs");
The problem i'm having right now is that all the posts are showing up on my user profile instead of only the posts published by the user.
Any suggestions?
Thanks
Upvotes: 0
Views: 61
Reputation: 317
Found the problem. The problem was I was subscribed to all the publications because I just subscribed somewhere random in my code.
I fixed this by adding a waitOn
in my route:
waitOn: function() {
return [
Meteor.subscribe("userJobs"),
];
},
Upvotes: 0
Reputation: 64312
When you make multiple subscriptions for the same collection, the results will be merged on the client. After subscribing to all_jobs
, the client will now have all of the jobs in its local database until the subscription is stopped. When you go to find
some of the jobs in the userJobs
template, you will need to indicate which ones you actually are interested in. Modify your helper as follows:
Template.userJobs.helpers({
jobs: function() {
return Jobs.find(userid: Meteor.userId());
}
});
Upvotes: 1