flatiron / cradle

a high-level CouchDB client for Node.js
MIT License
1.38k stars 182 forks source link

Design documents get put in "views" if they don't contain views #110

Open csm opened 12 years ago

csm commented 12 years ago

If you create a design document, but don't specify any views in that document (for example, if you just add filters or validate_doc_update to the document) cradle will put your document under "views". This breaks things, obviously.

The relevant code is:

// Design document
if (/^_design\/(\w|%|\-)+$/.test(id) && !('views' in doc)) {
    document.language = "javascript";
    document.views    =  doc;
} else {
    document = doc;
}

I worked around it in https://github.com/csm/cradle/commit/3f3f3e786ebeddef8921f45dea0a1ea1ab7024cc by just omitting the nonsense above. Maybe consider testing for the presence of other valid design document entries, so the change won't break code relying on the old behavior.

Also, a regex? Really?

mikepb commented 12 years ago

You can use db.put() to update a view without going through the magic.