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 #26116

Closed
maxime4000 opened this issue Aug 17, 2023 · 1 comment
Closed

Improvement on how relationName is generated #26116

maxime4000 opened this issue Aug 17, 2023 · 1 comment
Labels
domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. kind/improvement An improvement to existing feature and code.

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 ?

@jkomyno jkomyno transferred this issue from prisma/prisma-engines Jan 17, 2025
@jacek-prisma jacek-prisma added kind/improvement An improvement to existing feature and code. domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. labels Jan 17, 2025
@FGoessler
Copy link
Contributor

Hi,

We’ve noticed there hasn’t been activity on this issue for quite some time, and we suspect it might no longer be relevant. As part of our ongoing effort to streamline open issues in this repository, we’re closing this one to focus on what’s most important to our community.

If you believe this issue is still relevant and requires attention, feel free to reopen it. Reopening the issue is a valuable signal to us about what matters most to you.

You can learn more about our approach and motivations in the Prisma ORM Manifesto.

With love,
Your Prisma ORM Team ❤️

@FGoessler FGoessler closed this as not planned Won't fix, can't repro, duplicate, stale Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. kind/improvement An improvement to existing feature and code.
Projects
None yet
Development

No branches or pull requests

3 participants