Update with Foreign key
Hi, I have to update a table based on the foreign key. I am using nhost as the data provider.
4 Replies
stormy-goldOP•2y ago
mutate({
resource: "products",
values: {
name: "New Product",
material: "Wood",
},
id: 1,
});
instead of primary key, i want to change the record based on the foreign key
wise-white•2y ago
refine's data provider packages uses
id
primary key while sending requests. If you want, you can customize the data provider by copy-pasting the sourcecode to your project. But instead of this, how about using useUpdate
or useUpdateMany
(depends on your use case) and supplying the id
or ids
to change from a useList
hook with filters
?
Like, to get the primary key you can do a useList
and filter by your foreign key. Get the primary key and run the useUpdate
with your values and id
🤔stormy-goldOP•2y ago
okay..I will check that. Thank you.
wise-white•2y ago
Thought maybe those docs can help
Filtering in
useList
https://refine.dev/docs/api-reference/core/hooks/data/useList/#filtering
id
in useUpdate
https://refine.dev/docs/api-reference/core/hooks/data/useUpdate/#id-
Let me know if you have any issues while implementing this 🙏