ra-data-hasura-graphql icon indicating copy to clipboard operation
ra-data-hasura-graphql copied to clipboard

How can I have custom identifiers/primary keys for my resources?

Open akamit21 opened this issue 5 years ago • 9 comments
trafficstars

My table has a primary key other than id and react-admin enforces id to be returned in the response by the DataProvider. So can I configure different primary keys/identifiers for my resources?

akamit21 avatar Jul 21 '20 07:07 akamit21

hi Akamit21,

I am a novice (at least as a developer) myself but I hope this helps you.

In the readme for ra-data-hasura it has a section on different primary keys

best regards,

Chris

caston1981 avatar Jul 21 '20 12:07 caston1981

Have a similar question as @akamit21 !

(@affluent-bilby-classifieds that is for a different library that is not compatible with ra-data-hasura-graphql. I'm actually in the process of migrating from that library to this one.)

avimoondra avatar Jul 22 '20 19:07 avimoondra

A guess would be some modification here: https://github.com/Steams/ra-data-hasura-graphql#customize-fields-variables-responseparser ?

avimoondra avatar Jul 22 '20 19:07 avimoondra

Have a similar question as @akamit21 !

(@affluent-bilby-classifieds that is for a different library that is not compatible with ra-data-hasura-graphql. I'm actually in the process of migrating from that library to this one.)

Yes, I tried to implement but didn't work out.

akamit21 avatar Jul 23 '20 04:07 akamit21

Having the same issue, with the added complication that I am using composite primary keys. Did any of you figure it out?

polymeris avatar Aug 17 '20 13:08 polymeris

Nope, not yet, but to resolve my primary key problem I rename the primary key column to id when it fetches the data and generates the data-list, in that way I receive my primary-key column renamed as id.

akamit21 avatar Aug 18 '20 05:08 akamit21

@akamit21 can you show an example of your workaround on how you are renaming the primary key to id while fetching the data? it would be nice to have a option to configure that.

divramod avatar Dec 03 '20 18:12 divramod

@divramod agreed. @akamit21 could you show an example?

diazhector98 avatar Dec 06 '20 03:12 diazhector98

Well, I made the changes in getResponseParser.js file of the library. I had a employee table with primary_key name emoloyee_id. So I add only these line in code and it worked.

if (key === 'employee_id') { return { ...acc, id: dataKey }; }

akamit21 avatar Dec 11 '20 06:12 akamit21