Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -290,11 +290,13 @@ export default class AttributeApplicationValidator implements AstValidator<Attri
}
}

@check('@@unique')
@check('@@id')
@check('@@index')
Comment thread
ymc9 marked this conversation as resolved.
@check('@@unique')
// @ts-expect-error
private _checkUnique(attr: AttributeApplication, accept: ValidationAcceptor) {
const fields = attr.args[0]?.value;
const attrName = attr.decl.ref?.name;
if (!fields) {
accept('error', `expects an array of field references`, {
node: attr.args[0]!,
Expand All @@ -303,7 +305,7 @@ export default class AttributeApplicationValidator implements AstValidator<Attri
}
if (isArrayExpr(fields)) {
if (fields.items.length === 0) {
accept('error', `\`@@unique\` expects at least one field reference`, { node: fields });
accept('error', `\`${attrName}\` expects at least one field reference`, { node: fields });
return;
}
fields.items.forEach((item) => {
Expand All @@ -321,7 +323,7 @@ export default class AttributeApplicationValidator implements AstValidator<Attri
}

if (item.target.ref.$container !== attr.$container && isDelegateModel(item.target.ref.$container)) {
accept('error', `Cannot use fields inherited from a polymorphic base model in \`@@unique\``, {
accept('error', `Cannot use fields inherited from a polymorphic base model in \`${attrName}\``, {
node: item,
});
}
Expand Down
23 changes: 23 additions & 0 deletions tests/regression/test/issue-283.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { loadSchemaWithError } from '@zenstackhq/testtools';
import { describe, it } from 'vitest';

describe('Regression for issue #283', () => {
it('verifies issue 283', async () => {
await loadSchemaWithError(
`
model Base {
id Int @id @default(autoincrement())
x Int
type String
@@delegate(type)
}

model Sub extends Base {
y Int
@@index([x, y])
}
`,
'Cannot use fields inherited from a polymorphic base model',
);
});
});