diff --git a/packages/schema/src/language-server/zmodel-linker.ts b/packages/schema/src/language-server/zmodel-linker.ts index 13de8b968..56e2431d5 100644 --- a/packages/schema/src/language-server/zmodel-linker.ts +++ b/packages/schema/src/language-server/zmodel-linker.ts @@ -97,8 +97,7 @@ export class ZModelLinker extends DefaultLinker { container: AstNode, property: string, document: LangiumDocument, - extraScopes: ScopeProvider[], - onlyFromExtraScopes = false + extraScopes: ScopeProvider[] ) { if (this.resolveFromScopeProviders(container, property, document, extraScopes)) { return; @@ -106,17 +105,7 @@ export class ZModelLinker extends DefaultLinker { // eslint-disable-next-line @typescript-eslint/no-explicit-any const reference: DefaultReference = (container as any)[property]; - - if (onlyFromExtraScopes) { - // if reference is not resolved from explicit scope providers and automatic linking is not allowed, - // we should explicitly create a linking error - reference._ref = this.createLinkingError({ reference, container, property }); - - // Add the reference to the document's array of references - document.references.push(reference); - } else { - this.doLink({ reference, container, property }, document); - } + this.doLink({ reference, container, property }, document); } //#endregion diff --git a/packages/schema/src/language-server/zmodel-scope.ts b/packages/schema/src/language-server/zmodel-scope.ts index 9d685db27..48cf77995 100644 --- a/packages/schema/src/language-server/zmodel-scope.ts +++ b/packages/schema/src/language-server/zmodel-scope.ts @@ -224,7 +224,7 @@ export class ZModelScopeProvider extends DefaultScopeProvider { if (model) { const authModel = getAuthModel(getDataModels(model, true)); if (authModel) { - return this.createScopeForNodes(authModel.fields, globalScope); + return this.createScopeForModel(authModel, globalScope); } } return EMPTY_SCOPE; diff --git a/tests/integration/tests/regression/issue-1179.test.ts b/tests/integration/tests/regression/issue-1179.test.ts new file mode 100644 index 000000000..3d5fd8d99 --- /dev/null +++ b/tests/integration/tests/regression/issue-1179.test.ts @@ -0,0 +1,27 @@ +import { loadModel } from '@zenstackhq/testtools'; + +describe('issue 1179', () => { + it('regression', async () => { + await loadModel( + ` + abstract model Base { + id String @id @default(uuid()) + } + + model User extends Base { + email String + posts Post[] + @@allow('all', auth() == this) + } + + model Post { + id String @id @default(uuid()) + + user User @relation(fields: [userId], references: [id]) + userId String + @@allow('all', auth().id == userId) + } + ` + ); + }); +});