1

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.

  • possible duplicate of [Reactive updates when query is filtered by another query](http://stackoverflow.com/questions/10524482/reactive-updates-when-query-is-filtered-by-another-query) – user3374348 Oct 01 '14 at 11:00
  • You need a reactive join. See [this](https://www.discovermeteor.com/blog/reactive-joins-in-meteor/) and [this](http://stackoverflow.com/questions/20753279/publish-documents-in-a-collection-to-a-meteor-client-depending-on-the-existance). – David Weldon Oct 01 '14 at 16:13

0 Answers0