Models: Replace before.insert with autoValues

The before.insert hooks have the problem, that they are executed in a
different order if called from the client or from the server. If called
from the client, the before.insert hook is called before validation of
the schema, but if called from the server, the validation is called
first and fails.
This commit is contained in:
Alexander Sulfrian 2016-04-22 00:59:05 +02:00
parent 14e2b3c15f
commit a2888250f4
6 changed files with 129 additions and 75 deletions

View file

@ -14,6 +14,11 @@ UnsavedEditCollection.attachSchema(new SimpleSchema({
},
userId: {
type: String,
autoValue() { // eslint-disable-line consistent-return
if (this.isInsert && !this.isSet) {
return this.userId;
}
},
},
}));
@ -28,7 +33,3 @@ if (Meteor.isServer) {
fetch: ['userId'],
});
}
UnsavedEditCollection.before.insert((userId, doc) => {
doc.userId = userId;
});