Skip to main content

Multi-Table delete

Use the with parameter to delete records in one or more related tables as part of the primary deletion operation. This is useful for maintaining referential integrity by cleaning up associated data.

Basic multi-table delete

This example deletes a primary user record and all associated profile and posts records.

TypeScript
await manta.deleteRecords({
table: "user",
where: { id: 15 },
with: {
profile: {
on: { from: "id", to: "userId" }, // Maps user.id to profile.userId
},
posts: {
on: { from: "id", to: "authorId" }, // Maps user.id to posts.authorId
},
},
});

Conditional nested delete

Use the when clause inside the nested operation to apply the related delete only if the target linked record meets a specific condition.

TypeScript
await manta.deleteRecords({
table: "user",
where: { status: "inactive" },
with: {
profile: {
on: { from: "id", to: "userId" },
when: { verified: { equals: false } }, // Delete profile ONLY if verified is false
},
},
});