This question builds on a previous one (see here).
The dynamic subscription is set up with this code (slightly modified from the previous question):
Meteor.startup(function(){
Meteor.subscribe('parents');
Deps.autorun(function() {
parent = Parents.findOne({ _id: Session.get('parentId') });
if (!parent) return;
Meteor.subscribe('kids', parent);
});
});
The problem is that the server side must trust the parent
object that is passed by the client. Ideally, one would want to pass only the _id
of the parent object like this:
Deps.autorun(function() {
parentId = Session.get('parentId');
if (!parentId) return;
Meteor.subscribe('kids', parentId);
});
But, in this case, the dynamic subscription behavior breaks (e.g., the kids
collection is not updated on the client when the parent's children array is updated).
Why is Session.get('parentId')
less reactive than Parents.findOne({ _id: Session.get('parentId') })
, or has this to do with Meteor.subscribe('kids', parent)
vs. Meteor.subscribe('kids', parentId)
?
What would be the best pattern to coding this right?