Skip to content

Instantly share code, notes, and snippets.

@sorenbs
Created December 5, 2019 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sorenbs/0028d00379c5e669afe061578677778e to your computer and use it in GitHub Desktop.
Save sorenbs/0028d00379c5e669afe061578677778e to your computer and use it in GitHub Desktop.

Thanks Matt!

That is certainly a valid argument regarding implicit many-many relations, but not for the reason you have described. As I wrote in 339, I think implicit many-many is a solved problem: Introspection and Lift should both simply follow our convention when printing and reading the schema.


The main reason I am interested in including the implicit many-many syntax is that they enable a simpler Photon API for the majority that does not need extra fields on the relation table.

Traversing implicit many-many relation:

model User {
  posts Post[]
}

model Post {
  user User
  title String
}
prisma.users.findOne(...).posts()[o].title

Traversing explicit many-many relation:

model User {
  posts UserPost[]
}

model UserPost {
  user User
  post Post
}

model Post {
  user User
  title String
}
prisma.users.findOne(..., include: {posts: {post: true}}).posts()[0].post.title

So, the call to make is wether the gain from simpler Photon API is worth the extra complexity in the Schema (having both implicit and explicit many-many is more complex than just having the explicit version).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment