meteor-simple-schema: Autovalue not run for fields in an array of embedded documents when specified with a positional ("$") operator
Given a document with a field specified as an array of embedded documents, like so:
SubSchema = new SimpleSchema({
value: {
type: String,
autoValue: function() {
return "autovalue";
}
}
});
TestSchema = new SimpleSchema({
children: {
type: [SubSchema]
}
});
A modifier that updates a value within a single embedded document specified with a position operator (‘$’) will not trigger the autovalue. That is, the following doesn’t call the autovalue function:
var mod = {
$set: {"children.$.value": "should be overridden by autovalue"}
};
TestSchema.clean(mod, {isModifier: true});
Complete repro is at https://github.com/fongandrew/meteor-simple-schema-array-test
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 32
Has somebody tested this. for me it’s still not working.
+1 seems like the pull request has passing tests. Any reason not to merge it? It will soon be one year since the pull request was made.
Thanks for your patience. SimpleSchema 2.0.0-rc.1 is now released and should fix this bug.
There are a number of breaking changes when updating to 2.0, so be sure to check out the change log. If you use aldeed:collection2, you will need to use 2.10.0 or higher of that package in order to use SimpleSchema 2.0. If you use autoform, it is not yet updated to work with SimpleSchema 2.0, but hopefully soon.
SimpleSchema is now an isomorphic NPM package, so you can check out the updated readme and file issues over at the other repo. The Meteor wrapper package will exist for now but eventually I will probably deprecate support for it.
This is still a beta/RC and I do expect people will find issues, so use with caution. Production use is not yet recommended. That said, there are more and better unit tests than ever before, and the codebase should be much easier for others to read through and debug quickly.
@aldeed - I created a PR to fix this issue. Please review.
Something else to notice for all those who may be inspecting sibling values in their autoValue hooks for subschemas/subdocuments:
You may need to use
this.siblingField('subDocField')
when using $addToSet or $push andthis.field('subDocField')
when using $set.I believe this has something to do with
document.$.subDocField
being interpreted as being at the base level of the object bythis.siblingField
.No matter, this has a simple work around: