Skip to main content

Relationships

You can include related data from other tables using the with parameter.

Relationship parameters

ParameterTypeRequiredDescription
fieldsstring[]YesThe specific fields to return from the related table.
onobjectYesThe condition used to link the source table to the related table.
on.fromstringYesThe field in the source table used for the join condition.
on.tostringYesThe field in the related table used for the join condition.
filterRecord<string, any>NoAn optional filter object to apply to the related records.
withRecord<string, RelationshipOptions>NoAn object specifying additional related tables to include from this relationship.
pagenumberNoThe page number for paginating the related data.
listnumberNoThe number of records to return per page for the related data.
orderBystringNoThe field to sort the related data by.
order'asc' or 'desc'NoThe sort direction for the related data.

This example fetches support tickets and includes the associated user data for each ticket.

TypeScript
const tickets = await manta.fetchAllRecords({
table: 'support-tickets',
fields: ['ticket_id', 'subject'],
with: {
users: {
fields: ['first_name', 'last_name'],
on: { from: 'user_id', to: 'user_id' }
}
}
});

Multiple relationships

This example fetches support tickets and includes the users and the orders associated with each ticket.

TypeScript
const tickets = await manta.fetchAllRecords({
table: "support-tickets",
fields: ["ticket_id", "subject", "status"],
with: {
users: {
fields: ["first_name", "last_name"],
// from (source table => support-tickets), to (related table => users)
on: { from: "user_id", to: "user_id" },
},
orders: {
fields: ["product_name", "amount"],
// from (source table => support-tickets), to (related table => orders)
on: { from: "order_id", to: "order_id" },
},
},
page: 1,
list: 10,
});