Skip to content

Instantly share code, notes, and snippets.

@dminkovsky
Last active August 29, 2015 14:03
Show Gist options
  • Save dminkovsky/86d1bbdfa4762ebd2860 to your computer and use it in GitHub Desktop.
Save dminkovsky/86d1bbdfa4762ebd2860 to your computer and use it in GitHub Desktop.

users table:

[
  {
     id: 123,
     things: [1, 2, 3]
  }
]

things table:

[
  { id: 1, name: 'apple' },
  { id: 2, name: 'pear' },
  { id: 3, name: 'orange' }
]

Desired "joined" result:

{
  id: 123,
  things: [
    { id: 1, name: 'apple' },
    { id: 2, name: 'pear' },
    { id: 3, name: 'orange' }
  ]
}

This query works; but is it efficient? How else can this be done?

r.table('users').getAll('123').merge({
  things: r.row('things').map(function(thing) {
    return r.table('things').get(thing)
  })
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment