How to get relational data?
import { useResourceParams, useTable } from "@refinedev/core";
import { Card, Table } from "antd";
import React from "react";
import { useParams } from "react-router-dom";
export const CompanyContactsTable = () => {
const params = useParams();
const { tableProps } = useTable({
resource: "contacts",
});
return (
<Card title="contacts">
<Table {...tableProps} rowKey="id">
<Table.Column title="name" dataIndex="name" />
</Table>
</Card>
);
};
how can i get the conacts details when a user clicks on a company from the company page?
2 Replies
Hi @daw. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To fetch relational data in Refine, you can use the
useMany
hook. This hook fetches the data for the relevant posts or any other relational data you need. Here is an example of how you can use it:
In this example, useMany
is used to fetch the category data for each post. It takes the resource
and ids
as parameters. The resource
is the endpoint from where the data is fetched, and ids
is an array of ids that you want to fetch. The queryOptions
parameter is used to enable or disable the query based on certain conditions.
You can adapt this example to your needs by replacing "posts" and "categories" with "companies" and "contacts" respectively.
For more information, you can refer to the Refine documentation (https://refine.dev/docs/ui-integrations/ant-design/hooks/use-table#how-can-i-handle-relational-data).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@243918634374660098> kapa.ai is still learning and improving, please let us know how it did by reacting below