docs icon indicating copy to clipboard operation
docs copied to clipboard

Help Article: Implicit to Explicit Conversion

Open nurul3101 opened this issue 2 years ago • 7 comments

Help article for converting implicit many-to-many relations to explicit many-to-many

What issue does this fix?

  • https://github.com/prisma/docs/issues/3325

nurul3101 avatar May 12 '23 15:05 nurul3101

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 13, 2023 1:38pm

vercel[bot] avatar May 12 '23 15:05 vercel[bot]

This PR changes the following pages (Vercel Preview Deploy links):

Changed Vercel links

(Note that links will only be valid after Vercel preview deploy succeeded)

github-actions[bot] avatar May 12 '23 15:05 github-actions[bot]

Redirect check

This PR probably requires the following redirects to be added to static/_redirects:

  • This PR does not change any pages in a way that would require a redirect.

github-actions[bot] avatar May 12 '23 15:05 github-actions[bot]

I have made the change in code blocks. If it looks good, we can go ahead and merge it.

nurul3101 avatar Aug 31 '23 10:08 nurul3101

Ugh, how the deployment fails on Vercel is scary:

npm WARN deprecated [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm ERR! code E401
npm ERR! Incorrect or missing password.
npm ERR! If you were trying to login, change your password, create an
npm ERR! authentication token or enable two-factor authentication then
npm ERR! that means you likely typed your password in incorrectly.
npm ERR! Please try again, or recover your password at:
npm ERR!     https://www.npmjs.com/forgot
npm ERR! 
npm ERR! If you were doing some other operation then your saved credentials are
npm ERR! probably out of date. To correct this please try logging in again with:
npm ERR!     npm login
npm ERR! A complete log of this run can be found in:
npm ERR!     /vercel/.npm/_logs/2023-08-31T17_54_41_543Z-debug-0.log
Error: Command "npm install" exited with 1
image

janpio avatar Aug 31 '23 18:08 janpio

Question: Right now, the guide teaches how to create a new model to represent the relation table. Wouldn't it be possible to just reuse the already existing relation table that Prisma maintains for you?

nikolasburk avatar Sep 04 '23 15:09 nikolasburk

Thanks for this WIP PR, it just helped me out while migrating from an explicit to an implicit relation.


A few quick notes:

  • The docs for explicit relations use terms like CategoriesOnPosts where this guide uses UserPost (no "on", sigular) Ref: https://github.com/prisma/docs/pull/4768/files#diff-06e28c97d4e53bd73db1d585102122f2cf86088ce4e9e257d9a81bc2e8c26b6aR52
  • I had to change the relation part of the schema, nothing to delete as as second step IMO
    -  surveyResponseTopics SurveyResponseTopicsOnSurveyResponses[]
    +  surveyResponseTopics SurveyResponseTopic[]
    …
    -  surveyResponses SurveyResponseTopicsOnSurveyResponses[]
    +  surveyResponses SurveyResponse[]
    
  • I had to manually modify the migration in order to move the content of the old table:
    1. Move the DropTable to the end of the file
    2. Add a migration step right above. The order is special here according to the docs https://www.prisma.io/docs/orm/prisma-schema/data-model/relations/many-to-many-relations#columns "where A points to the model that comes first in the alphabet and B points to the model which comes last in the alphabet".
    -- Migrate data
    INSERT INTO "_SurveyResponseToSurveyResponseTopic"("A", "B") SELECT "surveyResponseId", "surveyResponseTopicId" FROM "SurveyResponseTopicsOnSurveyResponses";
    

tordans avatar Sep 25 '24 10:09 tordans

Could this be merged now? Stumbled upon this while looking for instructions on moving from implicit to explicit relations (specifically I want to have cascading deletes which aren't supported otherwise)

G2Jose avatar Oct 26 '24 22:10 G2Jose

Deploying docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 23f671c
Status: ✅  Deploy successful!
Preview URL: https://49341361.docs-51g.pages.dev
Branch Preview URL: https://nurul3101-patch-2.docs-51g.pages.dev

View logs

Dangerous URL check

No absolute URLs to prisma.io/docs found. No local URLs found.

github-actions[bot] avatar Nov 11 '24 15:11 github-actions[bot]

Where is this page in the website? I can't see it.

MansurAliKoroglu avatar Nov 27 '24 08:11 MansurAliKoroglu

@MansurAliKoroglu there was a mistake here. This PR should make it visible: https://github.com/prisma/docs/pull/6479

jharrell avatar Dec 03 '24 14:12 jharrell