iron-meteor / iron-router

A client and server side router designed specifically for Meteor.
MIT License
1.98k stars 412 forks source link

Weird issue with waitOn and Meteor.subscribe #586

Closed ramsaylanier closed 10 years ago

ramsaylanier commented 10 years ago

I have the following route:

    this.route('comicSingle', {
        path: '/comics/:id',
        waitOn: function(){
            console.log(this.params.id);
            return Meteor.subscribe('comicSingle', this.params.id);
        },
        data: function(){
            return Comics.findOne();
        }
    })

and the following publication on the server:

Meteor.publish('comicSingle', function(thisId){
    return Comics.find({id: thisId});
});

This is not working as expected - the Comic is not getting publish. HOWEVER, if I remove 'this.params.id' from the waitOn function and replace it with a hardcoded id, then it works.

Why would that be?

PeppeL-G commented 10 years ago

You log this.params.id in the console, does it show the correct value?

ramsaylanier commented 10 years ago

Yes - I got this to work by not using the id, but rather the title of the comic - which is also unique. I'm guessing it is an issue because the collection has both an _id field and an id field. The _id field is the id given to it by mongo, the id field is that id of the comic book as assigned to it by Marvel's API.

Anyway, problem solved I guess.