rethinkdb:在子项上使用父索引 table
rethinkdb: Using parent indices on a child table
假设我有两个 table:Car
和 Wheel
。一个 Car
有很多 Wheel
。 Car
有一个索引字段:Owner
.
现在,如果我想为 "Foo"
拥有的所有 Wheel
更改提要 ,那么我似乎必须复制 Wheel
table 上的 =17=] 字段,然后每当父 Car
更改时,我需要对子 Wheel
执行相同的更新——感觉就像虽然是一个糟糕的解决方案。
我尝试在引用父项的 Wheel
上添加 Owner
索引函数:
r.table('Wheel').indexCreate("Owner", function(wheel) {
return r.table('Car').get(wheel("CarID"))("Owner")
});
虽然这 returns "Index functions must be deterministic"
.
最好的方法是什么?
你是对的;您必须将 Owner
放到 Wheel
上,或者将轮子放入 Car
table 的数组中(这可能更常见)。 Changefeed 不能包含跨越多个 table 的谓词。
假设我有两个 table:Car
和 Wheel
。一个 Car
有很多 Wheel
。 Car
有一个索引字段:Owner
.
现在,如果我想为 "Foo"
拥有的所有 Wheel
更改提要 ,那么我似乎必须复制 Wheel
table 上的 =17=] 字段,然后每当父 Car
更改时,我需要对子 Wheel
执行相同的更新——感觉就像虽然是一个糟糕的解决方案。
我尝试在引用父项的 Wheel
上添加 Owner
索引函数:
r.table('Wheel').indexCreate("Owner", function(wheel) {
return r.table('Car').get(wheel("CarID"))("Owner")
});
虽然这 returns "Index functions must be deterministic"
.
最好的方法是什么?
你是对的;您必须将 Owner
放到 Wheel
上,或者将轮子放入 Car
table 的数组中(这可能更常见)。 Changefeed 不能包含跨越多个 table 的谓词。