Problem with nested create
Hi
I have a table that has 2 relationships with a different table. When I try to do a nested create it fails saying it requires
docGenerationId
Isn't it implied already?
The create command:
const docGeneration = await prisma.docGeneration.create({
data: {
id,
user: {
connect: { id: user.id },
},
workspace: {
connect: { id: workspaceId },
},
draftInput: {
create: {
id: inputId,
settings,
},
},
},
})
const docGeneration = await prisma.docGeneration.create({
data: {
id,
user: {
connect: { id: user.id },
},
workspace: {
connect: { id: workspaceId },
},
draftInput: {
create: {
id: inputId,
settings,
},
},
},
})
1 Reply
Schema:
model DocGeneration {
id String @id
userId String @map("user_id")
workspaceId String @map("workspace_id")
user User @relation(fields: [userId], references: [id])
workspace Workspace @relation(fields: [workspaceId], references: [id])
createdTime DateTime @default(now()) @map("created_time")
updatedTime DateTime @updatedAt @map("updated_time")
draftInputId String? @unique @map("draft_input_id")
draftInput DocGenerateInput? @relation("DraftDocGenerateInput", fields: [draftInputId], references: [id])
docGenerateInputs DocGenerateInput[] @relation("AllDocGenerateInputs")
@@index([userId, workspaceId, updatedTime(sort: Desc)])
@@map("doc_generation")
}
model DocGenerateInput {
id String @id
docGenerationId String @map("doc_generation_id")
settings Json
docGeneration DocGeneration? @relation("AllDocGenerateInputs", fields: [docGenerationId], references: [id])
draftForDocGeneration DocGeneration? @relation("DraftDocGenerateInput")
createdTime DateTime @default(now()) @map("created_time")
updatedTime DateTime @updatedAt @map("updated_time")
@@index([docGenerationId])
@@map("doc_generate_input")
}
model DocGeneration {
id String @id
userId String @map("user_id")
workspaceId String @map("workspace_id")
user User @relation(fields: [userId], references: [id])
workspace Workspace @relation(fields: [workspaceId], references: [id])
createdTime DateTime @default(now()) @map("created_time")
updatedTime DateTime @updatedAt @map("updated_time")
draftInputId String? @unique @map("draft_input_id")
draftInput DocGenerateInput? @relation("DraftDocGenerateInput", fields: [draftInputId], references: [id])
docGenerateInputs DocGenerateInput[] @relation("AllDocGenerateInputs")
@@index([userId, workspaceId, updatedTime(sort: Desc)])
@@map("doc_generation")
}
model DocGenerateInput {
id String @id
docGenerationId String @map("doc_generation_id")
settings Json
docGeneration DocGeneration? @relation("AllDocGenerateInputs", fields: [docGenerationId], references: [id])
draftForDocGeneration DocGeneration? @relation("DraftDocGenerateInput")
createdTime DateTime @default(now()) @map("created_time")
updatedTime DateTime @updatedAt @map("updated_time")
@@index([docGenerationId])
@@map("doc_generate_input")
}