File tree Expand file tree Collapse file tree 2 files changed +28
-3
lines changed
packages/language/src/validators Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -290,11 +290,13 @@ export default class AttributeApplicationValidator implements AstValidator<Attri
290290 }
291291 }
292292
293- @check ( '@@unique' )
294293 @check ( '@@id' )
294+ @check ( '@@index' )
295+ @check ( '@@unique' )
295296 // @ts -expect-error
296297 private _checkUnique ( attr : AttributeApplication , accept : ValidationAcceptor ) {
297298 const fields = attr . args [ 0 ] ?. value ;
299+ const attrName = attr . decl . ref ?. name ;
298300 if ( ! fields ) {
299301 accept ( 'error' , `expects an array of field references` , {
300302 node : attr . args [ 0 ] ! ,
@@ -303,7 +305,7 @@ export default class AttributeApplicationValidator implements AstValidator<Attri
303305 }
304306 if ( isArrayExpr ( fields ) ) {
305307 if ( fields . items . length === 0 ) {
306- accept ( 'error' , `\`@@unique \` expects at least one field reference` , { node : fields } ) ;
308+ accept ( 'error' , `\`${ attrName } \` expects at least one field reference` , { node : fields } ) ;
307309 return ;
308310 }
309311 fields . items . forEach ( ( item ) => {
@@ -321,7 +323,7 @@ export default class AttributeApplicationValidator implements AstValidator<Attri
321323 }
322324
323325 if ( item . target . ref . $container !== attr . $container && isDelegateModel ( item . target . ref . $container ) ) {
324- accept ( 'error' , `Cannot use fields inherited from a polymorphic base model in \`@@unique \`` , {
326+ accept ( 'error' , `Cannot use fields inherited from a polymorphic base model in \`${ attrName } \`` , {
325327 node : item ,
326328 } ) ;
327329 }
Original file line number Diff line number Diff line change 1+ import { loadSchemaWithError } from '@zenstackhq/testtools' ;
2+ import { describe , it } from 'vitest' ;
3+
4+ describe ( 'Regression for issue #283' , ( ) => {
5+ it ( 'verifies issue 283' , async ( ) => {
6+ await loadSchemaWithError (
7+ `
8+ model Base {
9+ id Int @id @default(autoincrement())
10+ x Int
11+ type String
12+ @@delegate(type)
13+ }
14+
15+ model Sub extends Base {
16+ y Int
17+ @@index([x, y])
18+ }
19+ ` ,
20+ 'Cannot use fields inherited from a polymorphic base model' ,
21+ ) ;
22+ } ) ;
23+ } ) ;
You can’t perform that action at this time.
0 commit comments