Composite Key support

441 views Asked by At

I have 2 primary keys acting as composite key id and language

Columns like below

id language_id Title
23           1 Food
23           2 Nourriture

getList, getOne always give results on english as id is taken as unique by react-admin.

Using Hasura GraphQL. Any solution how to fix this?

1

There are 1 answers

0
Gary Teichrow On

Probably not the answer you were looking for, but: IMO, composite keys on tables are best used as alternate unique keys and a surrogate primary key (e.g., Serial, etc) is then used as the PK on the table to give each tuple a unique 'simple' non-composite PK. The alternate PK (Id + LanguageId in your case) is then indexed and made unique. But that's database design advice not specific to RA.

As far as react-admin goes, as you now probably know, it really likes its resources to have a PK that is non-composite for the DataProvider/API. Think about it from a ReST POV and what the GET URI might look like.

In your case, to satisfy this in another way, you could think about returning from your API the composite of Id+LanguageId as a single attribute concatenated together (e.g., "23-1", "23-2", etc). Then RA might be happy with that resource.