jpillora
jpillora

Reputation: 5262

rethinkdb: Using parent indices on a child table

Let's say I have two tables: Car and Wheel. A Car has many Wheels. Car has an indexed field: Owner.

Now, if I wanted a change feed for all Wheels which are owned by "Foo", then it seems I have to duplicate the Owner field on the Wheel table and then whenever the parent Car changes, I'd need to perform the same update on child Wheels – this feels like a poor solution though.

I tried adding a Owner index function on Wheel referencing the parent:

r.table('Wheel').indexCreate("Owner", function(wheel) {
  return r.table('Car').get(wheel("CarID"))("Owner")
});

Though this returns "Index functions must be deterministic".

What is the best way to do this?

Upvotes: 0

Views: 42

Answers (1)

mlucy
mlucy

Reputation: 5289

You're right; you have to put Owner onto Wheel, or else put your wheels into an array in your Car table (which is probably more common). Changefeeds can't include predicates that span multiple tables.

Upvotes: 1

Related Questions