Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/schema/src/plugins/prisma/schema-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
]);
Expand Down Expand Up @@ -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)}`;
Expand Down
26 changes: 26 additions & 0 deletions tests/regression/tests/issue-1551.test.ts
Original file line number Diff line number Diff line change
@@ -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
}
`
);
});
});