When I try connecting a table row to another table...
# orm-help
t
When I try connecting a table row to another table, I get the following error:
Copy code
Type '{ 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
Copy code
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
Copy code
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?
āœ… 1
n
Hey Ted šŸ‘‹ I’m trying to reproduce this but your schema gives me an error:
Copy code
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?
Also, which database are you using here?
t
Oh, I forgot to add to the slack question in the model of ProfileType
user User[]
. I'll update the qestion
I'm using postgres
n
Does this code work for you?
Copy code
const allProfileTypes = await prisma.profileType.findMany({
  select: { id: true },
});

const profileType = allProfileTypes[0];
await prisma.user.create({
  data: {
    profileType: {
      connect: {
        id: profileType.id
      }
    }
  }
})
t
Yups! Oh man, can't believe I missed that!
Thank you for your helpf @nikolasburk
šŸ™Œ 1
n
No problem, happy to help šŸ˜„
ā¤ļø 1