I’ve read every post on this I can find and am stumped as to why my code is failing. Apologize if I’m being thick-headed, but I think I’m doing it right. However, I don’t get all of the fields published when a previous publish has limited the fields.
Why is my subscription to the single record not adding the ‘files’ field?
Template.turnovers.onCreated(function() {
var self = this;
self.turnover = new ReactiveVar(null);
self.tid = new ReactiveVar(null);
var pid = Session.get('current_project_id');
self.autorun(function() {
self.subscribe('turnovers_no_files', pid);
var t_sub = self.subscribe('turnover', self.tid.get());
if (t_sub.ready()) {
if (self.tid.get()) {
var t = Turnovers.findOne({'_id':self.tid.get()});
self.turnover.set(t);
console.log('"turnover" subscription is ready.')
} else {
console.log('turnover not yet selected');
}
} else {
console.log('"turnover" subscription not ready.');
}
});
});
Events
Template.turnovers.events({
'click .turnover-nav-link': function(event, template) {
event.preventDefault();
var tid = $(event.target).attr("my-data");
template.tid.set(tid);
},
});
Console (no “files” field?)
> Turnovers.find().fetch() // Only one record in the DB
[
_id: "NGfEFbCn67KHGnFBk"
date: "2015_10_06"
ingested: false
name: "MyTurnover_01"
]
Aloha - a couple of things to consider here that might help:
From the Meteor subscribe docs: “If more than one subscription sends conflicting values for a field (same collection name, document ID, and field name), then the value on the client will be one of the published values, chosen arbitrarily.”
By that logic, if I don’t specifically exclude the files field, then I should be ok, right? It still doesn’t seem to work. I thought I read something about meteor using a union of the fields in the collision.
Thanks for catching that and I was optimistic that was the issue! But, alas, still no files field. Should this work or are my expectations not correct?
DAAAAAHHH, that WAS the issue. When I fixed what you noted I forgot to add the .get() to the self.tid.get() change. So, this works now! I’ve updated the OP so it is a working example.
Thank you guys so much for taking the time to help me. Love this place.
I know this is a very old thread but seems like this problem is still present?
From the current docs:
Currently, when multiple subscriptions publish the same document only the top level fields are compared during the merge. This means that if the documents include different sub-fields of the same top level field, not all of them will be available on the client. We hope to lift this restriction in a future release. (Source)
Is there any way around this?
This has to be a pretty common problem, no?