Property 'xxx' is missing in type with relation

Hello, I am new to the prisma ecosystem and I am having a hard time understanding how it works. Here is my current .prisma file structure:
model GroupGraphics {
groupId Int @id
mainLogo String
group Group?
}
model GroupQA {
groupId Int @id
question String
answer String
group Group @relation(fields: [groupId], references: [id])
}
model Group {
id Int @id @default(autoincrement())
name String
description String[]
shopUrl String
graphics GroupGraphics @relation(fields: [id], references: [groupId] )
visible Boolean
faq GroupQA[]
}
model GroupGraphics {
groupId Int @id
mainLogo String
group Group?
}
model GroupQA {
groupId Int @id
question String
answer String
group Group @relation(fields: [groupId], references: [id])
}
model Group {
id Int @id @default(autoincrement())
name String
description String[]
shopUrl String
graphics GroupGraphics @relation(fields: [id], references: [groupId] )
visible Boolean
faq GroupQA[]
}
Here is my expected output (on select group)
{
"id": 0,
"graphics": { "mainLogo": "Some Values" },
"faq": [ { "question": "Hello", "answer": "World" } ]
}
{
"id": 0,
"graphics": { "mainLogo": "Some Values" },
"faq": [ { "question": "Hello", "answer": "World" } ]
}
The issue is that when I try to add to the database a new group, I get the following:
entityManager.group.create({
data: {
name: "Name",
description: ["Some Desc", "", ""],
shopUrl: "some-url",
faq: { create: [{ question: "MyQuestion", answer: "MyAnswer"}] },
graphics: { create: { mainLogo: "Some Logo" } } // <- **Property 'groupId' is missing in type '{ mainLogo: string; }' but required in type 'GroupGraphicsCreateWithoutGroupInput'.
}
});
entityManager.group.create({
data: {
name: "Name",
description: ["Some Desc", "", ""],
shopUrl: "some-url",
faq: { create: [{ question: "MyQuestion", answer: "MyAnswer"}] },
graphics: { create: { mainLogo: "Some Logo" } } // <- **Property 'groupId' is missing in type '{ mainLogo: string; }' but required in type 'GroupGraphicsCreateWithoutGroupInput'.
}
});
Can somebody tell me what I am missing exactly ? Thank you
4 Replies
Cold
Cold3w ago
On your groupId you are missing the @default param, unless you wanted to manually specify an ID in your code, which is what your model would imply Typically if you want an id that automatically populates you want to do something similar to what you've done in the Group model But in GroupGraphics and GroupQA there is no @default param
RaphaelEtim
RaphaelEtim2w ago
Hi @IgniteHost Like Cold already said, you are missing the groupId in the create section for both faq and graphics
faq: {
create: [
{ question: "MyQuestion", answer: "MyAnswer", groupId: 1} // use correct Id
]
},
graphics: {
create: {
groupId: 1, // Replace with the correct ID
mainLogo: "Some Logo"
}
}
faq: {
create: [
{ question: "MyQuestion", answer: "MyAnswer", groupId: 1} // use correct Id
]
},
graphics: {
create: {
groupId: 1, // Replace with the correct ID
mainLogo: "Some Logo"
}
}
You may want to review your schema to allow for groupId in GroupGraphics and GroupQA to be created by default so you wouldn't need to create them at every point.
IgniteHost
IgniteHostOP2w ago
What I want is to create the graphics with an auto generated id that will link my GroupGraphics to the graphics of my inserted group, not a hard coded id
RaphaelEtim
RaphaelEtim2w ago
@IgniteHost you would need to modify your schema for GroupGraphics. something along the lines of
model GroupGraphics {
groupId Int @id @default(autoincrement())
mainLogo String
group Group?
}

model GroupQA {
groupId Int @id @default(autoincrement())
question String
answer String
group Group @relation(fields: [groupId], references: [id])
}
model GroupGraphics {
groupId Int @id @default(autoincrement())
mainLogo String
group Group?
}

model GroupQA {
groupId Int @id @default(autoincrement())
question String
answer String
group Group @relation(fields: [groupId], references: [id])
}
Want results from more Discord servers?
Add your server