prisma-engines
prisma-engines copied to clipboard
Improvement on how relationName is generated
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 ?