Collection not ready in helper despite subscription


I’m having trouble with my Memberships collection not being available in a helper, when I subscribe to it in the OnCreated function - even though I have put the entire template inside a subscriptionsReady block


{{#if Template.subscriptionsReady}}
<hasMembership call in here>

OnCreated function

        var membershipsSub = Meteor.subscribe('userMembershipsPub');

Template Helper function:

 hasMembership: function(subjectId){            
        var m = Memberships.findOne(); // m is undefined, always
        //more code

I’ve debugged both server + client side simultaneously. What seems to be happening is that
(a) the template gets rendered (breakpoint in hasMembership helper gets hit)
(b) the server side publication (’usersMembershipPub’) gets called (breakpoint in this Pub gets hit)

Thus the collection is not ready (has no data) when the helper runs.
Why is this the case? I have used this same pattern elsewhere and it worked…besides, I thought Template.subscriptionsReady was supposed to take care of this exact issue?

Any help is appreciated. Thanks!


Try to change this:

var membershipsSub = Meteor.subscribe('userMembershipsPub');

To this:

var membershipsSub = this.subscribe('userMembershipsPub');

thanks. this works.

initially had tried this but didn’t work due to another mistake in my code…thanks for helping eliminate this as the cause!