Skip to content

Commit 028d0b6

Browse files
committed
fix(many-to-many): disable m-n-table generation
1 parent b4615e7 commit 028d0b6

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

prisma/dbml/schema.dbml

+12
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ Table Post {
2929
published Boolean [not null, default: false]
3030
author User
3131
authorId Int
32+
categories Category
33+
}
34+
35+
Table Category {
36+
id Int [pk, increment]
37+
name String [not null]
38+
posts Post
39+
}
40+
41+
Table CategoryToPost {
42+
categoryId Int [ref: > Category.id]
43+
postId Int [ref: > Post.id]
3244
}
3345

3446
Enum Role {

prisma/schema.prisma

+13-6
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,19 @@ model Profile {
3535
}
3636

3737
model Post {
38-
id Int @id @default(autoincrement())
39-
title String @default("")
40-
content String?
41-
published Boolean @default(false)
42-
author User? @relation(fields: [authorId], references: [id])
43-
authorId Int?
38+
id Int @id @default(autoincrement())
39+
title String @default("")
40+
content String?
41+
published Boolean @default(false)
42+
author User? @relation(fields: [authorId], references: [id])
43+
authorId Int?
44+
categories Category[]
45+
}
46+
47+
model Category {
48+
id Int @id @default(autoincrement())
49+
name String
50+
posts Post[]
4451
}
4552

4653
/// user role

src/cli/dbml-generator.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ export async function generate(options: GeneratorOptions) {
1111
const outputDir = options.generator.output!;
1212
const dbmlFileName =
1313
options.generator.config.outputName || defaultDBMLFileName;
14-
15-
const allowManyToMany = options.generator.config.manyToMany || true;
14+
const allowManyToMany =
15+
options.generator.config.manyToMany === 'false' ? false : true;
1616

1717
try {
1818
await mkdir(outputDir, { recursive: true });
1919

2020
// await writeFile('./test.json', JSON.stringify(options.dmmf.datamodel));
2121

22-
const dbmlSchema = generateDBMLSchema(options.dmmf, manyToMany);
22+
const dbmlSchema = generateDBMLSchema(options.dmmf, allowManyToMany);
2323

2424
await writeFile(join(outputDir, dbmlFileName), dbmlSchema);
2525
} catch (e) {

0 commit comments

Comments
 (0)