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 @@ -22,6 +22,7 @@ import { validateDuplicatedDeclarations } from './utils';
export default class DataModelValidator implements AstValidator<DataModel> {
validate(dm: DataModel, accept: ValidationAcceptor): void {
this.validateBaseAbstractModel(dm, accept);
this.validateBaseDelegateModel(dm, accept);
validateDuplicatedDeclarations(dm, getModelFieldsWithBases(dm), accept);
this.validateAttributes(dm, accept);
this.validateFields(dm, accept);
Expand Down Expand Up @@ -396,6 +397,15 @@ export default class DataModelValidator implements AstValidator<DataModel> {
);
});
}

private validateBaseDelegateModel(model: DataModel, accept: ValidationAcceptor) {
if (model.superTypes.filter((base) => base.ref && isDelegateModel(base.ref)).length > 1) {
accept('error', 'Extending from multiple delegate models is not supported', {
node: model,
property: 'superTypes',
});
}
}
}

export interface MissingOppositeRelationData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -714,4 +714,28 @@ describe('Data Model Validation Tests', () => {
errorLike(`The relation field "user" on model "A" is missing an opposite relation field on model "User"`)
);
});

it('delegate base type', async () => {
const errors = await safelyLoadModel(`
${prelude}

model Base1 {
id String @id
type String
@@delegate(type)
}

model Base2 {
id String @id
type String
@@delegate(type)
}

model A extends Base1,Base2 {
a String
}
`);

expect(errors).toMatchObject(errorLike(`Extending from multiple delegate models is not supported`));
});
});