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

Improvement on how relationName is generated #4144

Open
maxime4000 opened this issue Aug 17, 2023 · 0 comments
Open

Improvement on how relationName is generated #4144

maxime4000 opened this issue Aug 17, 2023 · 0 comments

Comments

@maxime4000
Copy link

So I work on a prisma generator. I'm trying to solve some relationship priorities like which one is the main Model and the other one is the relationship. Let's say a User own many Posts. I would think the relationName would be "UserToPost", but with my finding, the ${from}To${to} is not depending on who own the relation, but on which Model is first in the prisma schema.

So this model would generate User.fields.posts.relationName === "UserToPost"

model User {
  id    Int    @id @default(autoincrement())
  posts Post[]
}

model Post {
  id       Int  @id @default(autoincrement())
  author   User @relation(fields: [authorId], references: [id])
  authorId Int // relation scalar field  (used in the `@relation` attribute above)
}

But let's say you order your model alphabetically, the User.fields.posts.relationName === "PostToUser"

model Post {
 id       Int  @id @default(autoincrement())
 author   User @relation(fields: [authorId], references: [id])
 authorId Int // relation scalar field  (used in the `@relation` attribute above)
}

model User {
 id    Int    @id @default(autoincrement())
 posts Post[]
}

It can be ambigus is the relationship is Many-to-many, but I think it would be better if the relationName would slightly be more smart ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant