Created
          January 31, 2014 12:20 
        
      - 
      
- 
        Save svs/8731067 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # Given a table stat with primary key "slug" with data | |
| # [{slug: 'foo', stats: {}}, {slug:'bar', stats:{}}] | |
| updated_stats = { | |
| 'foo' => {a: 1, b: 2}, | |
| 'bar' => {a: 3, b: 4} | |
| } | |
| # I can do this | |
| updated_stats.each{|k,v| | |
| r.table('stats').get(k).update{|s| | |
| { :stats => updated_stats[k] } | |
| } | |
| } | |
| # so, why can't I do the following? | |
| r.table('stats').get_all(*updated_stats.keys).update{|s| | |
| { :stats => updated_stats[s["slug"]] } | |
| } | |
| # the rql shows nil as the value of updated_stats[s["slug"]] | |
| # any idea? thanks! | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
It's a tricky problem.
Here's the solution first.
Then
updated_statsis a ruby hash so when you use the brackets, it's the usual bracket operator, and sinceupdated_statsdoesn't have the key s["slug"], it returns nil.So you have to wrap
updated_statsinr.expr().Then brackets in ruby are used for
nth,get_field,sliceetc. 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 rethinkdb/rethinkdb#1179
Sorry you ran into this!