Ted Joe
09/15/2022, 1:53 PMType '{ id: string; }[]' has no properties in common with type 'ProfileTypeWhereUniqueInput'.ts(2559)
index.d.ts(17294, 5): The expected type comes from property 'connect' which is declared here on type 'ProfileTypeCreateNestedOneWithoutUserInput'
I have the following tables
model ProfileType {
id String @id @default(cuid())
name String @db.VarChar(255)
user. User[]
}
model User {
id String @id @default(cuid())
profileType ProfileType @relation(fields: [profileTypeId], references: [id])
profileTypeId String
}
Here's where I connect them
const allProfileTypes = await db.profileType.findMany({
select: { id: true },
})
const profileType = allProfileTypes[0]
await db.user.create({data: profileType: { connect: [{ id: profileType.id }] },})
What am I doing wrong and how can I fix them?nikolasburk
Error parsing attribute "@relation": The relation field `profileType` on Model `User` is required. This is no longer valid because it's not possible to enforce this constraint on the database level. Please change the field type from `ProfileType` to `ProfileType?` to fix this.
Which version of Prisma are you using?nikolasburk
Ted Joe
09/15/2022, 2:35 PMuser User[]
. I'll update the qestionTed Joe
09/15/2022, 2:35 PMnikolasburk
const allProfileTypes = await prisma.profileType.findMany({
select: { id: true },
});
const profileType = allProfileTypes[0];
await prisma.user.create({
data: {
profileType: {
connect: {
id: profileType.id
}
}
}
})
Ted Joe
09/15/2022, 2:40 PMTed Joe
09/15/2022, 2:40 PMnikolasburk