'How to specify names for implicit many-to-many relation table columns in Prisma?
I have this Prisma schema with a many to many relation between Authors and Posts:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
binaryTargets = ["native"]
}
model Author {
id String @id
posts Post[] @relation(name: "AuthorPostRelation")
}
model Post {
id String @id
authors Author[] @relation(name: "AuthorPostRelation")
}
Prisma (version 3.11.0) generates a table for the implicit relation with field A referencing Authors id and with field B referencing Post's id.
Is there a way to specify custom names for the relation table? E.g. author instead of A and post instead of B?
EDIT: I am aware that specifying custom field names is possible with explicit relation tables, but I'm specifically interested in implicit relation tables.
Solution 1:[1]
It is not possible yet to specify columns names in implicit relation tables.
For implicit relations, you need to adhere to the conventions of A and B as the table names.
However, this could possibly change in future and there is this GitHub Issue that tracks this.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Nurul Sundarani |
