Matthew Hammond
04/13/2022, 3:17 PMHi 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
}
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.
Nurul
04/14/2022, 8:29 AMconnect
operation.
Can you try this?
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: ExampleMatthew Hammond
04/14/2022, 9:40 AM