Composite primary key in RethinkDB

Is it possible to create a composite primary key in RethinkDB? For example, if I have a table with the following strucure documents {authorsId: '371df80c-2efd-48f9-ac37-3edcdb152fb1', postsId: '905e0c92-adcb-4095-98df-fa08ca71b900'}, how can I create a primary key together authorsIdand postsId. Or, if I cannot do this, how to use many, many relationships in three tables. Am I using one field as the primary key and the second as the secondary?

+4
source share
2 answers

Primary keys can only be on one column, but you can put postsIdit authorsIdin an array and use this as the value of the primary key.

. : https://www.rethinkdb.com/api/javascript/table_create/

, [postsId, authorsId] . ( ).

+2

RethinkDB , id. tableCreate, primaryKey, .

. . RethinkDB https://github.com/rethinkdb/rethinkdb/issues/1716.

, 3 , :

T1: id,

T2: id, fields2

P: t1_id, t2_id

eqJoin concatMap/getAll. :

r.table("P").eq_join("t1_id", r.table("T1"))
  .zip()
  .eq_join("t2_id", r.table("T2"))
  .zip()

, .

https://www.rethinkdb.com/docs/table-joins/#many-to-many-relations.

+1
source

Source: https://habr.com/ru/post/1614876/


All Articles