Closed RodolpheGohard closed 2 years ago
This is now possible with the option includeRelationFields
.
Update to the latest dev release npm install -D prisma-dbml-generator@dev
and add includeRelationFields
with false
to the dmbl generator.
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
generator dbml {
provider = "prisma-dbml-generator"
includeRelationFields = "false"
}
model Post {
id Int @id @default(autoincrement())
title String @default("")
content String?
published Boolean @default(false)
categories Category[]
}
model Category {
id Int @id @default(autoincrement())
name String
posts Post[]
}
The generated DBML Schema looks as follows:
//// ------------------------------------------------------
//// THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY)
//// ------------------------------------------------------
Table Post {
id Int [pk, increment]
title String [not null, default: '']
content String
published Boolean [not null, default: false]
}
Table Category {
id Int [pk, increment]
name String [not null]
}
Table CategoryToPost {
categoriesId Int [ref: > Category.id]
postsId Int [ref: > Post.id]
}
Awesome, exactly what I needed, many thanks !
If I take the example from the readme, I see that both the Category object in post and the category-to-post relation are represented in the output.
I think the relation-as-an-attribute object
categories Category
should not be represented because it duplicates what the relationship tableCategoryToPost
says. (In the ways traditionnal diagrams are shown, and concretely, the attribute doesn't exist in the SQL schema that would be generated)In this example, it's a Many to many, but this applies to One-To-Many as well.
Is there a workaround to hide these properties ?