Scope:createView can't add several views
Closed this issue · 2 comments
bergmark commented
It takes only one view as args, and adding a second one causes an Exception.Conflict.
Working solution:
__createViews : function (designDoc, args) {
var doc = {
ID : '_design/' + designDoc,
views : {}
}
Joose.A.each(args, function (arg) {
var view = doc.views[arg.name] = {}
view.map = arg.map.toString()
if (arg.reduce) view.reduce = arg.reduce.toString()
})
this.insertEntry(doc, 'store').now()
},
bergmark commented
... and sample usage
backend.__createViews("all", [{
name : "User",
map : function (doc) {
if (doc.className === "User") {
emit(null, doc);
}
}
}, {
name : "Transaction",
map : function (doc) {
if (doc.className === "Transaction") {
emit(null, doc);
}
}
}]).now();
bergmark commented
Closing this, check the pull request instead.