I’m trying to update a relational field: ```prisma...
# orm-help
b
I’m trying to update a relational field:
Copy code
prisma.practitioneer.update({
    where: {
      userID,
    },
    data: {
      image: {
        update: {
          where: { id: imageID },
          data: {
            image: image.data,
            type: image.type,
          },
        },
      },
    },
  });
But I’m getting this error:
Copy code
Unknown arg `image` in data.image for type practitioneerUncheckedUpdateInput. Did you mean `imageID`? Available args: …
If I try to change the query to (which is obviously wrong):
Copy code
prisma.practitioneer.update({
    where: {
      userID,
    },
    data: {
      imageID: {
        update: {
          where: { id: imageID },
          data: {
            image: image.data,
            type: image.type,
          },
        },
      },
    },
  });
I get the same error, only now it’s suggesting the correct field, the one it previously said it didn’t find:
Copy code
Unknown arg `imageID` in data.image for type practitioneerUncheckedUpdateInput. Did you mean `image`? Available args: …
r
@Bård 👋 Could you share the relevant schema as well?
b
Copy code
model practitioneer {
  id             Int            @id @default(autoincrement())
  key            String         @unique @default(uuid()) @db.Char(36)
  userID         String         @map(name: "user_id") @unique
  name           String         @db.VarChar(250)
  firstName      String         @db.VarChar(250)
  surname        String         @db.VarChar(250)
  birth          String         @default("") @db.VarChar(250)
  sex            String         @default("") @db.VarChar(250)
  email          String         @db.VarChar(50)
  phone          String         @db.VarChar(14)
  address        String         @default("") @db.VarChar(250)
  postal         String         @db.VarChar(20)
  postalLocation String         @db.VarChar(100)
  imageID        Int
  stateID        Int
  locationID     Int
  professionKey  String         @default("") @db.VarChar(20)
  experience     Int
  description    String         @default("") @db.VarChar(1000)
  clinicID       Int?
  externalID     Int?
  image          image          @relation(fields: [imageID], references: [id])
  user           User?          @relation(fields: [userID], references: [id])
  clinic         clinic?        @relation(fields: [clinicID], references: [id])
  location       location       @relation(fields: [locationID], references: [id])
  profession     profession     @relation(fields: [professionKey], references: [key])
  state          state          @relation(fields: [stateID], references: [id])
  activity       activity[]
  features       features[]
  products       products[]
  specialities   specialities[]

  @@index([clinicID], name: "idx_16432_clinicID")
  @@index([locationID], name: "idx_16432_location")
  @@index([professionKey], name: "idx_16432_profession")
  @@index([stateID], name: "idx_16432_state")
}
Copy code
model image {
  id            Int             @id @default(autoincrement())
  image         Bytes
  type          String
  practitioneer practitioneer[]
}
r
Image is just a single relation so you do not need
data
and
where
. Just pass whatever you would want to update directly under
image: { update: { …data } }
.
b
Ok, thanks for the help! On a side note: Isn’t this a bit wrong error message to get then?
r
Seems so. Could you open an issue about this here?
b
Thanks Ryan, I will see if I get the time. Got a lot on my plate atm 😅
👍 1
Hey @Ryan, I’m facing the same issue today. Regarding trying to query on relational fields, but the error message is saying the field name is wrong. Even though it is not. Same as yesterday.
Copy code
await prisma.practitioneer.update({
    where: {
      userID: req.userToken.uid,
    },
    data: {
      clinic: {
        delete: {},
      },
    },
  });
clinic is a relational field like so:
Copy code
clinic         clinic?        @relation(fields: [clinicID], references: [id])
Copy code
[0] Unknown arg `clinic` in data.clinic for type practitioneerUncheckedUpdateInput. Did you mean `clinicID`? Available args:
r
In this case, are your trying to remove the relation or delete the record?
b
I’m updating a table, and trying to delete it’s relation
r
This should work:
Copy code
await prisma.practitioneer.update({
    where: {
      userID: 'req.userToken.uid',
    },
    data: {
      clinic: {
        delete: true,
      },
    },
  })
delete
only needs a boolean as it’s just a single relation
b
Oh right! Cheers!
Guess I fell victim to the terrible error messages again
r
Are you using VSCode? If so it provides hints as to what’s needed in those parameters 😄
b
I am! And the hints are correct. But the hints won’t tell me to use boolean on the relation.
Just that the delete prop is available
Problem is that the error message says the whole relation field name is wrong. Which sends me bughunting in the complete wrong direction. Since the field name is correct, it’s just the syntax on the delete operation that is wrong.
r
I think you should get this at least:
b
You are correct!
Thanks for the tip
I submitted an issue about the error message
💯 1
r
Awesome! Thanks for that 😄