summaryrefslogtreecommitdiff
path: root/share/www
diff options
context:
space:
mode:
authorJohn Christopher Anderson <jchris@apache.org>2009-09-16 22:04:18 +0000
committerJohn Christopher Anderson <jchris@apache.org>2009-09-16 22:04:18 +0000
commit926af4ba11093dcaff13bea0e4ed9addfc67ab10 (patch)
tree40bec2163d0028d3e676eb0b47cebb634957c556 /share/www
parent3be897ebad528a81bcec91c406ea4e390f8a2915 (diff)
include_docs now take an _id (as well as a _rev) in the emitted value, to load docs other than the one doing the emitting. This means you can have one doc list a set of other docs to load in a single query. Enjoy!
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@815984 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'share/www')
-rw-r--r--share/www/script/test/view_include_docs.js26
1 files changed, 23 insertions, 3 deletions
diff --git a/share/www/script/test/view_include_docs.js b/share/www/script/test/view_include_docs.js
index 8d50784d..06aafc56 100644
--- a/share/www/script/test/view_include_docs.js
+++ b/share/www/script/test/view_include_docs.js
@@ -29,6 +29,9 @@ couchTests.view_include_docs = function(debug) {
with_prev: {
map: "function(doc){if(doc.prev) emit(doc._id,{'_rev':doc.prev}); else emit(doc._id,{'_rev':doc._rev});}"
},
+ with_id: {
+ map: "function(doc) {if(doc.link_id) { var value = {'_id':doc.link_id}; if (doc.link_rev) {value._rev = doc.link_rev}; emit(doc._id, value);}};"
+ },
summate: {
map:"function (doc) {emit(doc.integer, doc.integer)};",
reduce:"function (keys, values) { return sum(values); };"
@@ -84,6 +87,21 @@ couchTests.view_include_docs = function(debug) {
T(resp.rows.length == 1);
T(resp.rows[0].value == 4950);
+ T(db.save({
+ "_id": "link-to-10",
+ "link_id" : "10"
+ }).ok);
+
+ // you can link to another doc from a value.
+ resp = db.view("test/with_id", {key:"link-to-10"});
+ T(resp.rows[0].key == "link-to-10");
+ T(resp.rows[0].value["_id"] == "10");
+
+ resp = db.view("test/with_id", {key:"link-to-10",include_docs: true});
+ T(resp.rows[0].key == "link-to-10");
+ T(resp.rows[0].value["_id"] == "10");
+ T(resp.rows[0].doc._id == "10");
+
// Check emitted _rev controls things
resp = db.allDocs({include_docs: true}, ["0"]);
var before = resp.rows[0].doc;
@@ -91,11 +109,13 @@ couchTests.view_include_docs = function(debug) {
var after = db.open("0");
after.integer = 100;
after.prev = after._rev;
- T(db.save(after).ok);
+ resp = db.save(after)
+ T(resp.ok);
var after = db.open("0");
- T(after._rev != after.prev);
- T(after.integer == 100);
+ TEquals(resp.rev, after._rev, "fails with firebug running");
+ T(after._rev != after.prev, "passes");
+ TEquals(100, after.integer, "fails with firebug running");
// should emit the previous revision
resp = db.view("test/with_prev", {include_docs: true}, ["0"]);