diff --git a/packages/schema/src/plugins/prisma/schema-generator.ts b/packages/schema/src/plugins/prisma/schema-generator.ts index d84b3d0a9..a0a641b4c 100644 --- a/packages/schema/src/plugins/prisma/schema-generator.ts +++ b/packages/schema/src/plugins/prisma/schema-generator.ts @@ -442,7 +442,10 @@ export class PrismaSchemaGenerator { const addedRel = new PrismaFieldAttribute('@relation', [ // use field name as relation name for disambiguation - new PrismaAttributeArg(undefined, new AttributeArgValue('String', nameArg?.value || auxRelationField.name)), + new PrismaAttributeArg( + undefined, + new AttributeArgValue('String', nameArg?.value || auxRelationField.name) + ), new PrismaAttributeArg('fields', fieldsArg), new PrismaAttributeArg('references', referencesArg), ]); @@ -485,6 +488,9 @@ export class PrismaSchemaGenerator { // generate a fk field based on the original fk field const addedFkField = this.generateModelField(model, origForeignKey); + // `@map` attribute should not be inherited + addedFkField.attributes = addedFkField.attributes.filter((attr) => !('name' in attr && attr.name === '@map')); + // fix its name const addedFkFieldName = `${dataModel.name}_${origForeignKey.name}_${concreteModel.name}`; addedFkField.name = `${DELEGATE_AUX_RELATION_PREFIX}_${this.truncate(addedFkFieldName)}`; diff --git a/tests/regression/tests/issue-1551.test.ts b/tests/regression/tests/issue-1551.test.ts new file mode 100644 index 000000000..3a330de24 --- /dev/null +++ b/tests/regression/tests/issue-1551.test.ts @@ -0,0 +1,26 @@ +import { loadSchema } from '@zenstackhq/testtools'; +describe('issue 1551', () => { + it('regression', async () => { + await loadSchema( + ` + model User { + id Int @id + profile Profile? @relation(fields: [profileId], references: [id]) + profileId Int? @unique @map('profile_id') + } + + model Profile { + id Int @id + contentType String + user User? + + @@delegate(contentType) + } + + model IndividualProfile extends Profile { + name String + } + ` + ); + }); +});