Skip to main content

Hello,


I’m developing an Airtable App and I want to access to linked records of a given record.

When looking into the API doc the only way documented is using useRecords like following:


    const linkedTable = base.getTableByName("table1");
const linkedRecords = useRecords(
record.selectLinkedRecordsFromCell("table1", {
// Keep the linked records sorted by their primary field.
sorts: :{ field: linkedTable.primaryField, direction: "asc" }],
})
);

the issue is that I’m trying to do some logic in a non React coponent in a “Service” class, so I can’t use useRecords…


In the API docs they are talking about loading data, I tried loading data manually like so:


const table1QueryResult = await table1.selectRecords();
await table1QueryResult.loadDataAsync();
recordToMatch.selectLinkedRecordsFromCell("table1")

but I always get an error:

Error: LinkedRecordsQueryResult data is not loaded at LinkedRecordsQueryResult.get


Thank you,

Hey @Othman_Daid,


I think you’re seeing this error because you haven’t loaded the query result from your selectLinkedRecordsFromCell call.


You can use selectRecordsAsync and selectLinkedRecordsFromCellAsync to query your data and automatically load it:


Imagine you have a projects table, with a linked record field containing records from a tasks table. You could access the linked records like this:


// query projects and find a project record:
const projectsQuery = await projectsTable.selectRecordsAsync();
const projectRecord = projectsQuery.recordso0];

// query all the tasks within that project record:
const linkedTasksQuery = await projectRecord.selectLinkedRecordsFromCellAsync("Tasks");

// do something with that data:
console.log(`The ${projectRecord.name} project has these tasks:`, linkedTasksQuery.records);

// when you're done, remember to unload your data:
linkedTasksQuery.unloadData();
projectsQuery.unloadData();

Let me know if you have any followup questions!


Reply