Creating a new record that's related to an existing record and creates new relations?

Can you use this to created multiple levels of related records? https://www.prisma.io/docs/concepts/components/prisma-client/relation-queries#connect-an-existing-record i.e. the story app I'm working on. Users create a story which should connect to their user id, and they also write a chapter which connects to the story:
const story = await prisma.story.create({
data: {
connect: {
authorId: { user.id }
},
title: "The Fjord of the Things",
description: "Defintiely NOT a derivative work",
chapters: {
create: [
{
title: "A Non-Expected Party"
content: "Froyo Shmaggins decided to throw a party."
}
]
}
}
});
const story = await prisma.story.create({
data: {
connect: {
authorId: { user.id }
},
title: "The Fjord of the Things",
description: "Defintiely NOT a derivative work",
chapters: {
create: [
{
title: "A Non-Expected Party"
content: "Froyo Shmaggins decided to throw a party."
}
]
}
}
});
I'm not at my dev machine to check right now, but does that query look like it should hook everything up correctly?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server