Invalid SimpleSchema keys with nested autoValue

I have such a scheme (fluff cutting):

Schemas.people = new SimpleSchema({ note: { type: [Schemas.notes], optional: true, defaultValue: [] }, updates: { type: [Schemas.updates], optional:true, autoValue:function(){ if (this.isInsert) { return [{ at: new Date, user_id: this.userId }]; } return { $push:{ at: new Date, user_id: this.userId } } } } }); 

And the notes scheme looks like this:

 Schemas.notes = new SimpleSchema({ note: { type: String, autoform: { afFieldInput:{ type:"textarea" } }, optional: true }, updates: { type: [Schemas.updates], optional:true, autoform:{ omit:true }, autoValue:function(){ if (this.isInsert) { return [{ at: new Date, user_id: this.userId }]; } return { $push:{ at: new Date, user_id: this.userId } } } } }); 

And the update scheme is very simple:

 Schemas.updates = new SimpleSchema({ at: { type: Date }, user_id:{ type: Meteor.ObjectID } }); 

The "update" field in the people schema stores the date / user ID as expected when the update is made. However, it does not work in the notes schema:

 SimpleSchema invalid keys for "blablabla" context: 0: Object name: "note.0.updates.0.at" type: "keyNotInSchema" value: Mon May 11 2015 11:57:58 GMT-0400 (Eastern Daylight Time) 1: Object name: "note.0.updates.0.user_id" type: "keyNotInSchema" value: "abcd1234" 

I believe that the "name" should look like "people.note.0.updates.0.at", but I'm not sure that this assumption is true, and I'm completely not sure how to do it.

Update:

Code used to update people

  {{#autoForm collection="people" id=formId type="update" class="update" autocomplete="off" doc=getDocument autosave=true template="quickform"}} {{> afQuickField name='note' template="quickform" }} {{/autoForm}} 

formId returns a random identifier string and getDocument passes the correct collection.

Schemas.notes._schemaKeys does not list the at and user_id ... but Schemas.people._schemaKeys does.

People scheme: [..., "updates. $. At", "updates. $. User_id", ...]

Scheme of notes: ["note", "updates", "updates. $"]

How strange.

+5
source share
2 answers

Please note that Meteor uses the standard JavaScript syntax and therefore has the same limitations, for example, since you already realized that the order of the code is important.

We will see.

 Schemas.notes = new SimpleSchema({ updates: { type: [Schemas.updates] } } 

There are no nested functions in this code, so each line code will be executed before Meteor continues the next schema definition. Schema.updates will be dereferenced immediately, although it is not yet installed. type will be an array containing null , and finally SimpleSchema assumes that no fields are allowed at all.

+1
source

The problem is with the order in which the schemas are declared. What do I think makes sense? I posted “notes” before “updates,” and “people” were the last. Entering "updates" first completely fixed the problem.

I will talk about this as a possible error in the collection repository.

+1
source

All Articles