Skip to content

Commit

Permalink
fix(zmodel): don't inherit @@map attribute from base (#1172)
Browse files Browse the repository at this point in the history
  • Loading branch information
ymc9 authored Mar 25, 2024
1 parent a0ca15d commit f14f21b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/schema/src/utils/ast-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import {
Mutable,
Reference,
} from 'langium';
import { isAbsolute } from 'node:path';
import { URI, Utils } from 'vscode-uri';
import { findNodeModulesFile } from './pkg-utils';
import {isAbsolute} from 'node:path'

export function extractDataModelsWithAllowRules(model: Model): DataModel[] {
return model.declarations.filter(
Expand Down Expand Up @@ -68,6 +68,8 @@ export function mergeBaseModel(model: Model, linker: Linker) {
.filter((attr) => !attr.$inheritedFrom)
// don't inherit `@@delegate` attribute
.filter((attr) => attr.decl.$refText !== '@@delegate')
// don't inherit `@@map` attribute
.filter((attr) => attr.decl.$refText !== '@@map')
.map((attr) => cloneAst(attr, dataModel, buildReference))
.concat(dataModel.attributes);
}
Expand Down Expand Up @@ -142,8 +144,8 @@ export function resolveImportUri(imp: ModelImport): URI | undefined {
}

if (
!imp.path.startsWith('.') // Respect relative paths
&& !isAbsolute(imp.path) // Respect Absolute paths
!imp.path.startsWith('.') && // Respect relative paths
!isAbsolute(imp.path) // Respect Absolute paths
) {
imp.path = findNodeModulesFile(imp.path) ?? imp.path;
}
Expand Down
20 changes: 20 additions & 0 deletions tests/integration/tests/regression/issue-1167.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { loadSchema } from '@zenstackhq/testtools';

describe('issue 1167', () => {
it('regression', async () => {
await loadSchema(
`
model FileAsset {
id String @id @default(cuid())
delegate_type String
@@delegate(delegate_type)
@@map("file_assets")
}
model ImageAsset extends FileAsset {
@@map("image_assets")
}
`
);
});
});

0 comments on commit f14f21b

Please sign in to comment.