Skip to content

Instantly share code, notes, and snippets.

@neumino
Last active December 31, 2015 01:49
Show Gist options
  • Save neumino/7916270 to your computer and use it in GitHub Desktop.
Save neumino/7916270 to your computer and use it in GitHub Desktop.
ins0mnia -- IRC - 2013.12.11
r.db('todomvc').table('posts').map( function(post) {
return post.merge({
comments: r.db('todomvc').table('comments').filter( function(comment) {
comment("pid").eq( post("id") )
}).coerceTo("ARRAY")
})
})
// If you have an index on pid for the table comments, you can do
r.db('todomvc').table('posts').map( function(post) {
return post.merge({
comments: r.db('todomvc').table('comments').getAll(post("id"), {index: "pid"}).coerceTo("ARRAY")
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment