Skip to content

Commit 35d6bae

Browse files
feat(relationship): find correct relation
1 parent a9db1a2 commit 35d6bae

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

prisma/dbml/schema.dbml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ USER
3030

3131
Ref: Profile.userId - User.id
3232

33-
Ref: Post.authorId - User.id
33+
Ref: Post.authorId > User.id

src/index.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,23 @@ const generateRefs = (models: DMMF.Model[]): string[] => {
7575
.forEach((field) => {
7676
const relatedTables = field.relationName!!.split('To');
7777
refs.push(
78-
`Ref: ${relatedTables[0]}.${(field as any).relationFromFields[0]} - ${
78+
`Ref: ${relatedTables[0]}.${
79+
(field as any).relationFromFields[0]
80+
} ${getRefOperator(models, relatedTables[1], relatedTables[0])} ${
7981
relatedTables[1]
8082
}.${field.relationToFields!![0]}`
8183
);
8284
});
8385
});
8486
return refs;
8587
};
88+
89+
const getRefOperator = (
90+
models: DMMF.Model[],
91+
from: string,
92+
to: string
93+
): string => {
94+
const model = models.find((model) => model.name === from);
95+
const field = model?.fields.find((field) => field.type === to);
96+
return field?.isList ? '>' : '-';
97+
};

0 commit comments

Comments
 (0)