I am trying to create a table with linked records using a one-to-many relationship.
How would I create a Contacts table with a link to ContactPhones where a single Contact record is linked to multiple ContactPhones records?
Below is one of the things I have tried based on the base.createTableAsync and the FieldType documentation.
import { FieldType } from "@airtable/blocks/models";
import { useBase } from "@airtable/blocks/ui";
export async function createContactAirTables() {
const base = useBase();
if (!base.getTableByNameIfExists('ContactPhones_')){
await base.createTableAsync("ContactPhones_",
[
{name: 'Id', type: FieldType.SINGLE_LINE_TEXT},
{name: 'PhoneNumber', type: FieldType.SINGLE_LINE_TEXT}
]);
}
if (!base.getTableByNameIfExists('Contacts_')){
await base.createTableAsync("Contacts_",
[
{name: 'Id', type: FieldType.SINGLE_LINE_TEXT},
{name: 'BusinessName', type: FieldType.SINGLE_LINE_TEXT},
{name: 'ContactName', type: FieldType.SINGLE_LINE_TEXT},
{name: 'ContactPhones', type: FieldType.MULTIPLE_RECORD_LINKS,
options: {
linkedTableId: base.getTableByName('ContactPhones_').id
}
}
]);
}
};
This is the error I’m getting: