shahrukh ahmed
04/13/2022, 2:38 PMBrothak
04/13/2022, 2:45 PMMatthew 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.
shahrukh ahmed
04/13/2022, 4:36 PMscalar
means. For example take this sentence.
The following example includes a scalar list and a list of related models:
alexwasik
04/13/2022, 5:48 PMalexwasik
04/13/2022, 5:49 PMMove
which has matchId
and playerId
(among other things). I want to get all the moves for both players from the matchId
but I'm struggling to write the prisma query. DB is SQLitealexwasik
04/13/2022, 5:51 PMconst playersId = ['foo', 'bar'];
prisma.move.findMany({
where: {
matchId,
},
// Lost after this
});
alexwasik
04/13/2022, 6:03 PMawait prisma.move.findMany({
where: {
matchId,
playerId: {
in: players
}
},
});
Dog
04/13/2022, 9:00 PMawait prisma.tweet.findMany({
include: {
user: {
select: {
id: true,
displayName: true,
username: true,
},
},
},
});
I basically decide to take all fields from the user, besides the password. Is this the best way to do it? Since I might be using other models that require me to get the user, doing this on every query seems a bit repetitive. I was thinking I could do 2 things:
Have the private info of the user in 1 model and all the public one in another. So the User model would have an id, password and email and the Profile the username, displayName, etc. The second option would be to keep the models as they are and instead just save an object in another file that looks kinda like this
{
id: true,
displayName: true,
//etc
}
and then just put that in every select so that at least, if the user model changes, it updates in all queries that involve the user.Ian Ray
04/13/2022, 9:02 PMDog
04/13/2022, 9:02 PMDog
04/13/2022, 9:07 PMkyle travelet
04/13/2022, 10:18 PMJeremy Cohen Hoffing
04/13/2022, 11:13 PMMatt Young
04/14/2022, 12:23 AMMatt Young
04/14/2022, 12:24 AMBrothak
04/14/2022, 5:01 AMHwanseok Yu
04/14/2022, 6:45 AMBrothak
04/14/2022, 7:02 AMphil2srass
04/14/2022, 7:46 AMphil2srass
04/14/2022, 7:46 AMphil2srass
04/14/2022, 7:47 AMshahrukh ahmed
04/14/2022, 8:21 AMDanny SMc
04/14/2022, 10:55 AMyarn prisma generate
that would take into account the other *.schema
file(s) as well.
2. The ability to use multiple databases, I did find a github issue here, what is the actual status of this? As I see it was made almost 2 years ago: https://github.com/prisma/prisma/issues/1122Perez cato Cato perez
04/14/2022, 11:13 AMshahrukh ahmed
04/14/2022, 1:48 PMconst event = await prisma.posts.findUnique({
where: {
id: 1
}
});
Adam Boulila
04/14/2022, 2:30 PMGN Vageesh
04/14/2022, 5:07 PMGN Vageesh
04/14/2022, 5:07 PMGN Vageesh
04/14/2022, 5:08 PM