Hey guys, does anyone know if it's possible to eas...
# orm-help
j
Hey guys, does anyone know if it's possible to easily migrate an Implicit many to many relations table to an explicit many to many relation ?
r
@John McElreavey đź‘‹ It is, you would need to perform the following steps: 1. Create an explicit table in your
schema.prisma
whilst keeping the implicit relations. 2. Copy the data over from the implicit table to the explicit one. The table name for the implicit one with start with an underscore (
_
) 3. Then delete the implicit table and relations from
schema.prisma
.
t
Hmmm, I think there’s actually a pretty big step 2a in there which would be to rewrite all of your prisma queries that used the implicit many-to-many table to use the syntax for explicit tables as described in https://www.prisma.io/docs/support/help-articles/working-with-many-to-many-relations. Or is there an undocumented way to use the same queries for an explicit join table as you would use for an implicit join table @Ryan?
j
Yeah seems the many to many implicit relationship is great when you know you're not ever going to extend. But if you do then you need to manually migrate the data and then update all the connects to be creates among other things like joining onto the linking table first
t
Yeah, I guess the key word in your original question was easily
My personal impression after having done this transition once is that implicit many-to-many has a nice interface but probably shouldn’t get used in a production application that might need to change in the future.
j
Yeah I agree. I've used it in about 6 occasions in the current project I'm working on and I think I'll roll them out to explicit joins now before the application goes live just in case I ever need to extend them. Save myself the headache in future.