title: How's the best way to perform a nested concatMap to achieve joining multiple tables?
body: <p>on the concatMap api page in RethinkDB website, it's saying eqJoin is implemented with concatMap + getAll, which should provide better performance than other joins.</p>
  
  <p>in my case, I'd like to join multiple tables, here's an example, let's assume I have 3 tables, <code>users</code>, <code>departments</code> and <code>companies</code>. in every <code>user</code> document would contain a <code>department id</code> and <code>company id</code>. eg:</p>
  
  <pre><code>var user = {
    name: 'Peter',
    company: '12345',
    department: '8888',
    otherDetails: 'abc 123'
  }
  </code></pre>
  
  <p>the result I'd like to get after the join query is very similar to the result of a concatMap/eqJoin, but with all 3 tables:</p>
  
  <pre><code>[{
    user: {...},
    company: {...},
    department: {...}
  }, ...]
  </code></pre>
  
  <p>here is a query I've written that could get the result:</p>
  
  <pre><code>r.table('users')
    .concatMap(function(user) {
      return r.table("companies").getAll(
        user("company")
      ).map(function(company) {
        return { user: user, company: company }
      })
    })
    .concatMap(function(row) {
      return r.table("departments").getAll(
        row("user")("department")
      ).map(function(department) {
        return { user: row("user"), company: row("company"), department: department }
      })
    })
  </code></pre>
  
  <p>my questions:</p>
  
  <ol>
  <li>is there a better way to do this?</li>
  <li>is the performance of the above query still as good as usual eqJoin on 2 tables?</li>
  <li>is the performance of using merge much worse than using eqJoin (concatMap) in these cases?</li>
  </ol>
  
  <p>thanks much.</p>