billysometimes / rethinkdb

dart driver for rethinkDB
MIT License
37 stars 19 forks source link

Query that runs in Data Explorer but won't compile in Dart #32

Closed dotlambda closed 9 years ago

dotlambda commented 9 years ago

I have tried the following query in the Data Explorer:

r.db('test').table('teams').get("c525f3e4-4aff-4423-b85c-e9ac9a1f7738").update({
  'members': {'d429f4f3-edd0-41a5-a981-39e5db507760': {
    'role': r.row('members')('d429f4f3-edd0-41a5-a981-39e5db507760')('role').default('user')
  }}
})

and it works. I then translated it to Dart:

Map response = await r.table('teams').get(teamId).update({
  'members': {user.id: {'role': r.row('members')(user.id)('role').rqlDefault('user')}}
}).run(connection);

But sadly this throws a RqlCompileError:

r.row is not defined in this context.

This is the data I use:

r.db('test').table('teams').insert([
  {
    'creatorId': 'd429f4f3-edd0-41a5-a981-39e5db507760',
    'id': 'c525f3e4-4aff-4423-b85c-e9ac9a1f7738',
    'members': {
      '5cff7d1c-e0c1-4d45-84d3-1001ef08af0d': { role: 'user' },
      '85257fce-9bd7-4b31-9d50-ca2f626a04e5': { role: 'user' },
      'd429f4f3-edd0-41a5-a981-39e5db507760': { role: 'admin' }
    },
    'name': 'Team Conner'
    }
  }
])
billysometimes commented 9 years ago

Thanks for filing! Should be fixed now, the function short-cut r.row wasn't getting wrapped properly.