I want to find out if it is possible or request a ...
# orm-help
t
I want to find out if it is possible or request a few features related to disconnecting relations. I didn't see anything when searching the Issues, but I cannot imagine that these feature requests haven't been made before. 1. Exclusively update relation - The idea is that if I pass in 2 records that I want to have related to a model and i know that no other records should be related, it should automatically run the query to disconnect any other records that don't match. 2. Connect/Disconnect via where - Instead of having to declare each record to connect/disconnect, the relation could include the ability to add a where clause independent of the unique constraints. ex. If I want to disconnect all Posts from users who are marked as deleted, or connect a Post to all tags created in the last 10 days (these are kinda stupid use cases, but off the top of my head)
d
1) Should already work via
set
. Is that what you're looking for? 2) is a valid feature request and can be filed on github: https://github.com/prisma/prisma
t
awesome, I was wondering about #1 because it seemed so obvious of a use case
the documentation seems to only mention set as it related to removing all o2m relations, i guess it makes sense that underlying that is because it works as above, but I now see that it is also described here
to be clear about how set works, does it leave records in place if they don't need to be modified? (I ask because I often store created dates on my m2m relationships and would hate to lose the history)
also the documentation seems unclear on how it works with relation tables
r
It doesn’t leave the records in place,
set
replaces the records with the ones you provide.
The mechanism is same for relation tables,
set
will work on the relation table in that case.
t
so it deletes all the rows and adds the new ones?
r
Yes.