Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit many to many relationships with/without extra columns #816

Closed
divyenduz opened this issue Oct 21, 2019 · 5 comments
Closed

Explicit many to many relationships with/without extra columns #816

divyenduz opened this issue Oct 21, 2019 · 5 comments
Assignees
Labels
Milestone

Comments

@divyenduz
Copy link
Contributor

divyenduz commented Oct 21, 2019

Tracks implementation of https://github.com/prisma/specs/tree/master/schema#explicit-many-to-many-mn-relationships-with-or-without-extra-columns

Many-to-many relation with/without extra columns.

@divyenduz divyenduz transferred this issue from prisma/migrate Oct 22, 2019
@pantharshit00 pantharshit00 added the kind/feature A request for a new feature. label Oct 22, 2019
@nikolasburk
Copy link
Member

There's also a related discussion here: prisma/specs#264

@ifndefdeadmau5
Copy link

ifndefdeadmau5 commented Dec 12, 2019

Here I update temporary workaround by @matthewmueller (in slack channel) that possibly can be migrate into official implementation in future This isn't right, see below

model Blog {
  id       Int       @id
  authors  Writer[]
}
model Writer {
  id      Int     @id
  blogs   Blog[]
}
// many to many
model BlogsWriters {
  id        Int      @id
  blog      Blog
  author    Writer
  is_owner  Boolean
}

also suggested migration steps:

  1. remove the @id from id
  2. add @id([blog, author]), if that works... great, you don't have to migrate any data. if that doesn't work, you'll need to write a script to de-dupe
  3. remove id Int entirely

@scriptcoded
Copy link

@ifndefdeadmau5 This won't actually work as of right now. The following schema has been tested and works :)

model Blog {
  id      Int          @id
  authors BlogWriter[]
}
model Writer {
  id    Int          @id
  blogs BlogWriter[]
}
// many to many
model BlogWriter {
  id       Int     @id
  blog     Blog
  author   Writer
  is_owner Boolean
}

@janpio janpio added this to the Preview 24 milestone Mar 3, 2020
@narciero
Copy link

narciero commented Mar 3, 2020

what is the status of prisma supporting extra data fields with M-N relation?

@janpio
Copy link
Member

janpio commented Mar 19, 2020

This is now implemented 🚀

@janpio janpio closed this as completed Mar 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants