Exercise 1: Implicit Many-to-Many and connectOrCreate — Possible Solution =========================================================================== schema.prisma (add): model Post { // ...existing fields tags Tag[] } model Tag { id Int @id @default(autoincrement()) name String @unique posts Post[] } $ npx prisma migrate dev --name add-tags $ npx prisma generate Make sure the "prisma" tag already exists: await prisma.tag.create({ data: { name: "prisma" } }); One create call: const post = await prisma.post.create({ data: { title: "Tagging posts", slug: "tagging-posts", author: { connect: { email: "alan@example.com" } }, tags: { connectOrCreate: [ { where: { name: "prisma" }, create: { name: "prisma" } }, { where: { name: "typescript" }, create: { name: "typescript" } }, ], }, }, include: { tags: true }, }); console.log(post.tags.map((t) => t.name)); // [ 'prisma', 'typescript' ] "prisma" is linked (connected), and "typescript" is created and linked. In Prisma Studio: the Tag table has both tags, and the relation is shown on each Post and Tag. The underlying join table, _PostToTag, holds two rows linking the post's id to the two tag ids. WHY THIS WORKS AS AN ANSWER ------------------------------ connectOrCreate handles "existing" and "new" tags in one call, and the author is linked with connect rather than a foreign key, which is the style nested writes need. The whole create runs as a single transaction.