Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compound primary key in RethinkDB

Tags:

rethinkdb

Can I create compound primary key in RethinkDB ? For example if I have table with next documents strucure {authorsId: '371df80c-2efd-48f9-ac37-3edcdb152fb1', postsId: '905e0c92-adcb-4095-98df-fa08ca71b900'} how can I create primary key on both together authorsId and postsId. Or if I cannot do this how should I use many to many relationship in three tables way. Have I use one field as primary key and second as secondary index ?

like image 457
abilash Avatar asked Nov 07 '15 17:11

abilash


1 Answers

Primary keys can only be on one column but you can put postsId and authorsId in an array and use that as primary key value.

See here for more information: https://www.rethinkdb.com/api/javascript/table_create/

EDIT

The primary key is still just one field but you can use [postsId, authorsId] as the value for that column and achieve the same. (added back from comment to answer).

like image 148
Oliver Avatar answered Sep 19 '22 00:09

Oliver