Exception when joined collection is updated and reactive is enabled
Closed this issue · 4 comments
First, thanks for making this library available!
We're using it to make a reactive join between 2 collections, similar to this:
Company {
name
}
Document {
name,
companyId,
}
The relationship is defined as:
Companies = new Meteor.Collection('companies');
Documents = new Meteor.Collection('documents');
Documents.join(Companies, "companyId", "company", ["name"]);
Then we publish the list of documents:
const cursor = Documents.find();
return Documents.publishJoinedCursors(cursor, { reactive: true }, this);
From there we display the data, with the library working as expected.
Then we update the database:
- Update the first document's name: OK
- Update the first company's name: FAILED
The first update works as expected, with the page reactively updated without the need of refresh.
The second update generates the exception below on the server:
Exception in changed observe/observeChanges callback: ReferenceError: Random is not defined
at Object.changed (packages/perak_joins.js:275:104)
at _CachingChangeObserver.changed (packages/minimongo/local_collection.js:1315:28)
at applyChange.changed (packages/minimongo/local_collection.js:727:27)
at runWithEnvironment (packages/meteor.js:1188:24)
at packages/meteor.js:1201:14
at packages/mongo/observe_multiplex.js:182:30
at Array.forEach (<anonymous>)
at Function._.each._.forEach (packages/underscore.js:139:11)
at Object.task (packages/mongo/observe_multiplex.js:176:9)
at Meteor._SynchronousQueue.SQp._run (packages/meteor.js:819:16)
I've created a branch on a Meteor+React repo to reproduce the error.
Clone the branch:
git clone -b perak-joins-issue-random-not-defined git@github.com:leite08/Create-React-Meteor-App.git
Run:
meteor npm install --save react react-dom
meteor
On a Mongo shell, run:
db.companies.update({},{$set:{name:'aaa'}});
That should generate the exception above.
Curiously, the exception also happens when the reactive
option is ommited.