Skip to content

Commit ba8a888

Browse files
authored
fix(delegate): generated fk fields shouldn't inherit @map attribute from its origin (#1633)
1 parent da69e02 commit ba8a888

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

packages/schema/src/plugins/prisma/schema-generator.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,10 @@ export class PrismaSchemaGenerator {
442442

443443
const addedRel = new PrismaFieldAttribute('@relation', [
444444
// use field name as relation name for disambiguation
445-
new PrismaAttributeArg(undefined, new AttributeArgValue('String', nameArg?.value || auxRelationField.name)),
445+
new PrismaAttributeArg(
446+
undefined,
447+
new AttributeArgValue('String', nameArg?.value || auxRelationField.name)
448+
),
446449
new PrismaAttributeArg('fields', fieldsArg),
447450
new PrismaAttributeArg('references', referencesArg),
448451
]);
@@ -485,6 +488,9 @@ export class PrismaSchemaGenerator {
485488
// generate a fk field based on the original fk field
486489
const addedFkField = this.generateModelField(model, origForeignKey);
487490

491+
// `@map` attribute should not be inherited
492+
addedFkField.attributes = addedFkField.attributes.filter((attr) => !('name' in attr && attr.name === '@map'));
493+
488494
// fix its name
489495
const addedFkFieldName = `${dataModel.name}_${origForeignKey.name}_${concreteModel.name}`;
490496
addedFkField.name = `${DELEGATE_AUX_RELATION_PREFIX}_${this.truncate(addedFkFieldName)}`;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { loadSchema } from '@zenstackhq/testtools';
2+
describe('issue 1551', () => {
3+
it('regression', async () => {
4+
await loadSchema(
5+
`
6+
model User {
7+
id Int @id
8+
profile Profile? @relation(fields: [profileId], references: [id])
9+
profileId Int? @unique @map('profile_id')
10+
}
11+
12+
model Profile {
13+
id Int @id
14+
contentType String
15+
user User?
16+
17+
@@delegate(contentType)
18+
}
19+
20+
model IndividualProfile extends Profile {
21+
name String
22+
}
23+
`
24+
);
25+
});
26+
});

0 commit comments

Comments
 (0)