RethinkDB 子查询示例错误

RethinkDB subquery sample error

http://www.rethinkdb.com/docs/table-joins/ 上标题为 "Using subqueries" 的示例无法按预期工作。除了 lambda 一词的拼写错误外,您能否提出修复建议?

http://www.rethinkdb.com/docs/table-joins/ 中发布的示例是 Python 示例。如果您想尝试 Ruby 中的示例,请尝试在 irb 中输入以下查询:

r.table("companies").get(id).merge{ |company| { 
     :employees => r.table('employees')
       .get_all(company['id'], :index => 'company_id')
       .coerce_to('array') }
  }.run(Conn)

该查询的结果应如下所示:

irb(main):254:0> r.table("companies").get(id).merge{ |company| {
irb(main):255:2*      :employees => r.table('employees')
irb(main):256:2>        .get_all(company['id'], :index => 'company_id')
irb(main):257:2>        .coerce_to('array') }
irb(main):258:1>   }.run(Conn)
=> {"company"=>"Starfleet", "company_id"=>"064058b6-cea9-4117-b92d-c911027a725a", "employees"=>[], "id"=>"064058b6-cea9-4117-b92d-c911027a725a", "name"=>"Jean-Luc Picard", "rank"=>"captain", "type"=>"paramilitary"}

确保在您 运行 查询之前创建了所有适当的表和索引:

// Create the tables
r.table_create("companies").run(Conn)
r.table_create("employees").run(Conn)

// Create the index
r.table("employees").index_create("company_id").run(Conn)

// Insert a document
r.table("companies").insert({
    "id": "064058b6-cea9-4117-b92d-c911027a725a",
    "name": "Jean-Luc Picard",
    "company_id": "064058b6-cea9-4117-b92d-c911027a725a",
    "rank": "captain",
    "company": "Starfleet",
    "type": "paramilitary"
}).run(Conn)