Skip to content

Instantly share code, notes, and snippets.

@avanslaars
Last active May 4, 2016 20:46
Show Gist options
  • Save avanslaars/b836699325322277180debb8ea2d963e to your computer and use it in GitHub Desktop.
Save avanslaars/b836699325322277180debb8ea2d963e to your computer and use it in GitHub Desktop.
r.db('demo').table('people')
.eqJoin('id', r.db('demo').table('pets'), {index:'owner_id'})
.group('left')
.pluck('right')
.ungroup()
.map(group => ({
person: group('group'),
pets: group('reduction').map(pet => pet('right'))
}))
r.db('demo').table('people').innerJoin(r.db('demo').table('pets'), (personRow, petRow) => personRow('id').eq(petRow('owner_id')))
r.db('demo').table('people').outerJoin(r.db('demo').table('pets'), (personRow, petRow) => personRow('id').eq(petRow('owner_id')))
/*
optional group, zip and pluck to get to the specifics of the pet
.group('left').zip().pluck('name', 'type')
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment