My schema looks like this:
model User {
id Int @default(autoincrement()) @id
createdAt DateTime @default(now())
email String @unique
role String @default("user")
sessions Session[]
profile Profile?
goalBoard GoalBoard[]
team Team[]
...
}
model GoalBoard {
id Int @default(autoincrement()) @id
active Boolean // Whether an active goalBoard
owner User @relation(fields: [ownerId], references: [id])
ownerId Int
createdAt DateTime @default(now())
goal Goal[]
...
}
model Goal {
id Int @default(autoincrement()) @id
status String
createdAt DateTime @default(now())
owner User @relation(fields: [ownerId], references: [id])
ownerId Int
goalBoard GoalBoard @relation(fields: [goalBoardId], references: [id])
goalBoardId Int
content String
goalFrequency GoalFrequency[]
task Task[]
}
model Task {
id Int @default(autoincrement()) @id
status String // incomplete, complete
createdAt DateTime @default(now())
content String
goal Goal @relation(fields: [goalId], references: [id])
goalId Int
}
I am writing a mutation function which takes an array of goal
objects. These goal
objects have nested array of task
objects. It looks like this:
const goals = [
{
title: 'string',
...
tasks: [
{
deadline: "2020/10/10",
...
}
]
},
...
]
How would I handle such structure using Prisma2? There are multiple writes & connectOrCreate
logic required.
Here is my failed attempt to write an insertion in the Db. Testing with just one insertion & connection.
const returnGoals = await db.goal.create({
data: {
content: "test goal",
owner: {
connect: {
id: ctx.session!.userId,
},
},
goalBoard: {
create: { // warns that create is incorrectly used here
active: true,
owner: {
connect: {
id: ctx.session!.userId,
},
},
},
},
},
});
Your schema with this example did not have an issue to use this create
result
Maybe your issue with the rest of your hide schema content