```Hi Everyone, I have an error I need some help w...
# orm-help
m
Copy code
Hi Everyone, I have an error I need some help with.
We have a table called users that has some columns that are foreign keys. organization_id is the first foreign key in this table.
The issue is that when using update in prisma.users.update I can't update fields which are foreign keys in the users table in my sql database. I can't find
information related to this in the documentation. The sql query below does the update but does not work when I use update with prisma.

This query works: 
const result = await prisma.$queryRaw`UPDATE users
SET name=${bodyData.name}, email=${bodyData.email}, roles=${bodyData.roles} , organization_id=${parseInt(bodyData.organization_id)}
WHERE users.id = ${parseInt(bodyData.id)}`;

This doesn't work: 

await prisma.users.update({
    where: {
      id: parseInt(bodyData.id),
    },
    data: {
      name: bodyData.name,
      email: bodyData.email,
      roles: bodyData.roles,
      organization_id: bodyData.organization_id,
    },
});

We get this error: 

Unknown arg `organization_id` in data.organization_id for type usersUpdateInput. Did you mean `organizations`? Available args:
type usersUpdateInput {
  id?: BigInt | BigIntFieldUpdateOperationsInput
  name?: String | NullableStringFieldUpdateOperationsInput | Null
  auth0_id?: String | NullableStringFieldUpdateOperationsInput | Null
  email?: String | NullableStringFieldUpdateOperationsInput | Null
  roles?: String | NullableStringFieldUpdateOperationsInput | Null
  inserted_at?: DateTime | DateTimeFieldUpdateOperationsInput
  updated_at?: DateTime | DateTimeFieldUpdateOperationsInput
  organizations?: organizationsUpdateOneWithoutUsersInput
}
Copy code
If I wanted to update the value of these foreign keys in my update using prisma, how could I do this? Here is my prisma.users.update that is causing the error:
Organization_id is the first foreign key in my table and trying to update this is what causes the error. I can update the fields before that are not foreign Organization_id with no issue.
My prisma schema matches the database.
n
Hey Matthew ๐Ÿ‘‹ It seems you are looking for
connect
operation. Can you try this?
Copy code
await prisma.users.update({
    where: {
      id: parseInt(bodyData.id),
    },
    data: {
      name: bodyData.name,
      email: bodyData.email,
      roles: bodyData.roles,
      organization: {
        connect: { id: bodyData.organization_id },
      },
    },
});
Hereโ€™s an example of connect with update operation: Example
๐Ÿ˜ 1
m
Thank you so much Nurul! This worked perfectly ๐Ÿ’ฏ
๐Ÿ™Œ 1