I have a one-to-many 'you may also like' relationship between product
documents in my Product collection. These are stored in a ymal.product_ids
array on the master product document.
In the Iron Router controller for the product show template, I have two subscriptions: one for the product itself, and one for the 'you may also like' products:
@AdminProductsShowController = @AdminController.extend
waitOn: ->
Meteor.subscribe 'product', @params._id
Meteor.subscribe 'you_may_also_like_products', @params._id
...
The publish function for you_may_also_like_products
is:
Meteor.publish 'you_may_also_like_products', (style_number) ->
product = Product.first(style_number: style_number)
unless product.ymal is undefined
Product.find(
_id:
$in: product.ymal.product_ids
)
In my template, I can add a new product to the `you_may_also_like_products' array by calling a Meteor method.
Meteor.call('add_ymal_product', @_id, form_data.style_number, (error, result) ->
)
So far so good. If I refresh the page manually, the new product appears in the you_may_also like collection, because the subscription has been made again. My problem is that, without refreshing the page, I can't find a way to get the you_may_also_like_products
subscription to return the updated dataset.
I'm sure this is meant to be very basic Meteor stuff; but I've read every Stack Overflow question that's similar, and watched the recommended eventedmind.com tutorials.