react-admin dataprovider 指定一个自定义字段作为主键 - 一个未命名为“id”的字段
我在react-admin ra-data-hasura
中使用hasura数据提供程序(但我确信它或多或少与ra-data-graphql
相同) )
我的实体的主键的名称与 id
不同
是否可以将未命名的字段设置为主要字段id
例如:MyEntityId
是否可以按资源指定它(因为每个表都可以有自己的名称模式) )或全局
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
亚历克斯,
您在文档中找到了答案: https://marmelab.com/react-admin/FAQ.html#can-i-have-custom-identifiersprimary-keys-for-my-resources
你必须解决这是在
dataProvider
级别。您必须实现自己的 dataProvider 的方法,将您的
MyEntityId
字段映射到react-admin 所需的id
字段。例如(实现getList方法):
Alex,
You have that answer in the docs: https://marmelab.com/react-admin/FAQ.html#can-i-have-custom-identifiersprimary-keys-for-my-resources
you have to resolve this at the
dataProvider
level.You have to implement your own dataProvider's methods that mapped your
MyEntityId
field to theid
field required by react-admin.For example (implementing getList method):
是的,您可以自定义缓存 ID 对 typePolicies 选项中的每种类型使用
keyFields
href="https://www.apollographql.com/docs/react/caching/cache-configuration/#configuration-options" rel="nofollow noreferrer">InMemoryCache 构造函数:Yes, you can customize the cache IDs using the
keyFields
for each type in thetypePolicies
option of the InMemoryCache constructor: