It's a tricky problem.
Here's the solution first.
r.table('stats').get_all(*updated_stats.keys).update{|s|
{ :stats => r.expr(updated_stats).get_field(s["slug"]) }
}.run()
Then updated_stats
is a ruby hash so when you use the brackets, it's the usual bracket operator, and since updated_stats
doesn't have the key s["slug"], it returns nil.
So you have to wrap updated_stats
in r.expr()
.
Then brackets in ruby are used for nth
, get_field
, slice
etc. And when given a variable, it cannot guess which one it should use.
So you have to explicitly say you want to use get_field
.
We will add a bracket term, which should fix this problem -- see https://github.com/rethinkdb/rethinkdb/issues/1179
Sorry you ran into this!