Hi, as far as i know it's not possible to fetch other documents in any of the design functions. (is this changed?)
What you could do is to have the schema in your design document, like it is done here: https://github.com/TravisPaul/couchapp-schema The design functions are executed in the scope of the design document (litle unsure if there are exeptions), so "this" is the design document. So the couchapp-schema can use this.schema[newDoc.schema] to get the schema. You would still have to update the design document, but you don't have to touch the validation function. regards, Stefan 2014-08-29 15:50 GMT+02:00 Conor Mac Aoidh <[email protected]>: > Hi All, > > I'm writing a validate_doc_update function at the moment. I want to > validate that document inserts comply with a strict schema. I have been > thinking of how to do this, without making the validate function too > inefficient. > > Since there is no way to pass parameters to the validate_doc_update > function, I was thinking of fetching the schema (contained in a local JSON > file) asynchronously. This could be a terrible idea. However, I've found > that I can request the schema once and then store it. So, there would be > one initial performance hit in fetching the file, and from then on it would > be saved. See the example function: > / > //function validate(new_doc, old_doc, userCtx){// > // if(typeof this.schema == 'undefined')//{// > // // get the schema// > // }// > // // make sure new_doc conforms to the this.schema[new_doc.type]// > //}/ > > I'm just wondering, is there a better way to do this? Are there any > compelling reasons not to do this? > > Also, I have considered just including the schema statically in the > function but the solution above is preferable as the schema changes often > and I don't want to have to update the design functions. > > Thanks > > Conor >
