Hey everyone. I'm encountering some interesting be...
# orm-help
a
Hey everyone. I'm encountering some interesting behaviour when using prisma. It is related to prisma's generated types, and I've been skimming the docs trying to find out more, but there doesn't seem to be much info about generated types in there (please correct me if I'm mistaken). Here's the behaviour: Say I have a model with two 1-1 relations (Profile in the example below):
Copy code
// prisma.js

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator client {
  provider = "prisma-client-js"
}

model User {
  id      Int      @id @default(autoincrement())
  name    String
  profile Profile?
}

model Profile {
  id      Int    @id @default(autoincrement())
  name    String
  userId  Int?
  user    User?  @relation(fields: [userId], references: [id])
  photoId Int?
  photo   Photo? @relation(fields: [photoId], references: [id])
}

model Photo {
  id      Int      @id @default(autoincrement())
  url     String
  profile Profile?
}
The following code works when creating a new profile:
Copy code
const user = await prisma.user.create({ data: { name: "TestUser" } });    
const profile = await prisma.profile.create({
  data: {
    name: "TestProfile",
    user: { connect: { id: user.id } },
    photo: { create: { url: "<http://example.com/img>" } },
  },
});
... but this fails with an error
Copy code
const user = await prisma.user.create({ data: { name: "TestUser" } });
const profile = await prisma.profile.create({
  data: {
    name: "TestProfile",
    userId: user.id,
    photo: { create: { url: "<http://example.com/img>" } },
  },
});
The error is:
Copy code
Unknown arg `userId` in data.userId for type ProfileCreateInput. Did you mean `user`? Available args:
type ProfileCreateInput {
  name: String
  user?: UserCreateNestedOneWithoutProfileInput
  photo?: PhotoCreateNestedOneWithoutProfileInput
}
Would anyone be able to tell me where to look to learn more about what is happening here?
r
@Anirudh Nimmagadda 👋 You cannot mix passing the id directly and using
connect
or
create
in the same query. If you’re using
connect
/`create` then you need to use only that anywhere. A combination is not allowed.