how can I use `prisma.user.updateMany` and disconn...
# orm-help
f
how can I use
prisma.user.updateMany
and disconnect a list using
data: {discoonect: {id: 1}}
?
g
to disconnect you need to do:
Copy code
await this.prisma.$disconnect();
are you wanting to update some users and then fetch them and then disconnect?
f
Not that kind of disconnect, I'm talking about the connect and disconnect using
implicit many to many
but I need to update many users that are conncted by the id
i
just replace
someField
with your relation
f
I want to delete the connection from all the users that have the ids
User model: id Servers[] Server model: id User[] I want to remove a server, which means i need to disconnect all users that are in the server
how would i do that?
disconnect all users by server id
i
if you want to remove the server, you probably don't have to disconnect the users. If you define your relation properly, i.e. use
onDelete
it should be removed as soon as you exec
prisma.server.delete()
f
ah i see
f
I see, thanks. Just curious though, what if in the future, I want to do this but without deleting the server, how would i disconnect ?
i
just make the relations optional (so the user can exist even if you remove the server) and use onDelete: SetNull
f
Hmm.
But i dont get why i can curently disconnect one user and not multiple
i
you were passing a single object in what you've pasted. Have you tried the example I gave you? One with an array of objects?
f
I get error when i use it with
deleteMany
I wanna disconnect ONE server from many users
i
how does you model look like? Both User and Server?
f
Copy code
User model:
   id int id
   Servers[]
Server model:
   id int id
   User[]
like this
no @relation
i
There has to be a relation to do that
how does it look like in your schema.prisma file?
Yeah, you need to fix your models. You need to make a relation between them
or it's actually an implicit many to many... so it should be kind of automatic
f
🤔
just to be clear,
update
works,
updateMany
show an error
i
can you show the full error? I can't see it all in the screenshot you've posted before
but then what happens if you just remove the Server? I believe that's what you wanted eventually? It wouldn't delete your Users right?
f
What if i wanna kick multiple users from the server? but not all
i
then we'd have to make disconnect working on updateMany 😄 or delete on UsersOnServers model if accessible in implicit many to many?
f
huh