Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,18 @@ export default class DataModelValidator implements AstValidator<DataModel> {
relationOwner = field;
}
} else {
[field, oppositeField].forEach((f) => {
if (!this.isSelfRelation(f, thisRelation.name)) {
accept(
'error',
'Field for one side of relation must carry @relation attribute with both "fields" and "references" fields',
{ node: f }
);
}
});
// if both the field is array, then it's an implicit many-to-many relation
if (!(field.type.array && oppositeField.type.array)) {
[field, oppositeField].forEach((f) => {
if (!this.isSelfRelation(f, thisRelation.name)) {
accept(
'error',
'Field for one side of relation must carry @relation attribute with both "fields" and "references" fields',
{ node: f }
);
}
});
}
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,23 @@ describe('Data Model Validation Tests', () => {
}
`);

// many-to-many implicit
//https://www.prisma.io/docs/concepts/components/prisma-schema/relations/many-to-many-relations#implicit-many-to-many-relations
await loadModel(`
${prelude}
model Post {
id Int @id @default(autoincrement())
title String
categories Category[]
}

model Category {
id Int @id @default(autoincrement())
name String
posts Post[]
}
`);

// one-to-one incomplete
expect(
await loadModelWithError(`
Expand Down