Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Counts is getting the same number of comments for each post #70

Closed
adavia opened this issue Oct 11, 2015 · 2 comments
Closed

Counts is getting the same number of comments for each post #70

adavia opened this issue Oct 11, 2015 · 2 comments

Comments

@adavia
Copy link

adavia commented Oct 11, 2015

Lets say im showing a list of posts with each corresponding number of comments. For some reason i get the same number of comments for each post when ever i add or remove comments. This is happening when i do return Counts.get("comments-count") but it works fine if i do return Comments.find({postId: postId}).count();
This is my code so far:

post_item.html

<template name="postItem">
  <li>{{name}} <span class="pull-right"> {{commentsCount}}</span></li>
</template>

post_item.js

Template.postItem.onCreated(function() {
  return this.subscribe('comments', this.data._id);
});

Template.postItem.helpers({
  commentsCount: function() {
    return Counts.get('comments-count'); // This works: Comments.find({postId: this._id}).count(); 
  }
});

comments.js

Meteor.publish('comments', function(postId) {
  Counts.publish(this, 'comments-count', Comments.find({postId: postId}));
  return Comments.find({postId: postId});
});
@boxofrox
Copy link
Contributor

I believe this is answered here. Let me know if it doesn't.

@adavia
Copy link
Author

adavia commented Oct 12, 2015

Excelent. Just what i needed.

@adavia adavia closed this as completed Oct 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants