Hi,

I'm trying to use recursion in a view... maybe.

Actually, I'm trying to use one GET to retrieve a document and its (possibly nested) snippets.

{_id: "TestDoc", type: "doc", title: "Test Title"}

{_id: "snip1", type: "snip", parent: "TestDoc", contents: "...", order: 1} {_id: "snip1a", type: "snip", parent: "snip1", contents: "...", order: 1} {_id: "snip1b", type: "snip", parent: "snip1", contents: "...", order: 2} {_id: "snip2", type: "snip", parent: "TestDoc", contents: "...", order: 2}

So, I tried cmlenz's blog post with View Collation (http://www.cmlenz.net/archives/2007/10/couchdb-joins ), but it only did one level. I like the approach of the snippets being their own docs, because I think (hope) the update volume on those will be high.

I'm wondering if there are other goodies like map() available in view functions. Will I need to call this()? Should I have the child doc / snip keep track of its parent's ids as I've laid out above? It seems like this might lead to a lot of calls instead of the single call I want to make.

It just doesn't feel right to have the parents keep track of its children's ids, for chance of orphaning, maint. nightmares, and more. Who knows, maybe it's a better approach. Even if I take that route, when iterating thru the children of a doc, how do I recursively call the function? Can there be subfuns in Javascript (well, CouchDB views)?

Or a totally new approach is warranted?

Cheers,
BA


Reply via email to