national-gold
national-gold7mo ago

Relation table supabase api call

I have a table named lot, and a table named components In lot table, I have a field name component_id which is foreign key map to components table How can I get components table data when getting lot data in list page for lot?
2 Replies
kapa.ai
kapa.ai7mo ago
Hi @tandeptraiso1. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- You can achieve this by using the useTable hook provided by Refine and passing a select value in the meta object to perform a relational database operation. This is done using the Supabase select property internally. Here is an example of how you can do this:
const { tableProps, sorter } = useTable<ILot>({
resource: "lots",
meta: {
select: "*, components(title)",
},
});
const { tableProps, sorter } = useTable<ILot>({
resource: "lots",
meta: {
select: "*, components(title)",
},
});
In this example, ILot is the TypeScript interface for your lot data. The select property in the meta object is used to get the title data from the components table and display it on the List page. You can then use the tableProps in your table component to display the data. For more information, you can refer to the Refine Supabase documentation (https://refine.dev/docs/data/packages/supabase#select---handling-one-to-many-relationship). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai7mo ago
<@369510721135837184> kapa.ai is still learning and improving, please let us know how it did by reacting below