Search code examples
meteoriron-router

Meteor iron-router subscription. How to make subscriptions with a few linked parameters?


I'm got a route with few subscriptions where each one with some parameters for limiting data. Already known parameter only for first subscription, but all other based on data from item of first subscription. How i can handle it? Example (coffeescript):

Router.route '/survey/:id/',
    name: 'survey',
    waitOn: ->
        Meteor.subscribe 'surveys', @params.id
        Meteor.subscribe 'projects'. project_id # WHERE project_id is Survey.findOne(@params.id).project_id
        Meteor.subscribe 'squestions', squestions_ids # WHERE squestions_ids is Projects.findOne(project_id).questions

I see one way how to solve it... i can make 'publish' what that returns few cursors, but in real i got subscriptions much more than 3 so name of this subscription should be like survey_with_project_questions_somemore_somemore2_somemore3_and_so - it's ugly! Does exist some way to solve it?


Solution

  • You can use packages that handle joins for you, like:

    https://github.com/englue/meteor-publish-composite

    https://github.com/svasva/meteor-publish-with-relations

    The first one is more up to date, so you should probably use this one