0

I'm trying to do multiple eq_joins. The error I get is:

ReqlQueryLogicError: Primary keys must be either a number, string, bool, pseudotype or array (got type OBJECT):
{
        "First name":   "John",
        "Last name":    "Urquhart",
        "employers":    [
                {
                        "date_hired":   "2-Mar-88",
                        "organization_id":      "2a5e2e3d-275a-426e-9ecd-0bd5601bff6b"
                }
        ],
        "id":   "e70d5350-c1e0-41ee-a1cc-6638c7136d89",
        "primary_photo":        "http://www.kingcounty.gov/~/media/safety/sheriff/Sheriff_Urquh in:
r.db('public').table(u'police_internal_affairs_allegations').filter(lambda var_24: var_24.coerce_to('string').match(u'(?i).*?Urquhart.*?')).eq_join(u'organization_id', r.db('public').table(u'organizations')).merge(lambda var_25: r.expr({'right': var_25['right'].coerce_to('array').map(lambda var_26: [(r.expr(u'organization_') + var_26[0]), var_26[1]]).coerce_to('object')})).zip().eq_join(u'person_id', r.db('public').table('people')).merge(lambda var_27: r.expr({'right': var_27['right'].coerce_to('array').map(lambda var_28: [(r.expr(u'person_') + var_28[0]), var_28[1]]).coerce_to('object')})).zip()

My code is:

ids_for_other_tables = [field for field in fields if field.endswith('_id')]
modified_joined_data = []
for field in ids_for_other_tables:

    special_names = {'person': 'people'}
    t = special_names[field[:-3]] if field[:-3] in special_names else field[:-3]+'s'
    dbobj = getattr(dbobj, 'eq_join')(field, r.db("public").table(t))

    dbobj = dbobj.merge(  lambda row: {'right': row['right'].coerce_to('array').map(
                  lambda pair: [r.expr(field[:-2]) + pair[0], pair[1]]
                ).coerce_to('object')})
    dbobj = dbobj.zip()

The purpose of this code is auto join info from tables for all fields ending in _id

Tim Clemans
  • 176
  • 1
  • 1
  • 7

1 Answers1

1

It's hard to say without looking at the data in your table, but it looks like the problem is that one of the fields you're trying to eq_join on has an object in that field instead of an ID. I'd run the part of the query before the eq_join and make sure it has the format you're expecting.

mlucy
  • 5,249
  • 1
  • 17
  • 21