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/language/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,14 +561,20 @@ export function getAllAttributes(

if (isDataModel(decl) && decl.baseModel) {
if (decl.baseModel.ref) {
attributes.push(...getAllAttributes(decl.baseModel.ref, seen));
const attrs = getAllAttributes(decl.baseModel.ref, seen).filter((attr) => !isNonInheritableAttribute(attr));
attributes.push(...attrs);
}
}

attributes.push(...decl.attributes);
return attributes;
}

function isNonInheritableAttribute(attr: DataModelAttribute) {
const attrName = attr.decl.ref?.name ?? attr.decl.$refText;
return ['@@map', '@@unique', '@@index'].includes(attrName);
}

/**
* Retrieve the document in which the given AST node is contained. A reference to the document is
* usually held by the root node of the AST.
Expand Down
13 changes: 1 addition & 12 deletions packages/sdk/src/prisma/prisma-schema-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,7 @@ export class PrismaSchemaGenerator {
}
}

const allAttributes = getAllAttributes(decl).filter(
(attr) => this.isPrismaAttribute(attr) && !this.isInheritedMapAttribute(attr, decl),
);
const allAttributes = getAllAttributes(decl).filter((attr) => this.isPrismaAttribute(attr));

for (const attr of allAttributes) {
this.generateContainerAttribute(model, attr);
Expand Down Expand Up @@ -241,15 +239,6 @@ export class PrismaSchemaGenerator {
return getStringLiteral(defaultSchemaField?.value) ?? 'public';
}

private isInheritedMapAttribute(attr: DataModelAttribute, contextModel: DataModel) {
if (attr.$container === contextModel) {
return false;
}

const attrName = attr.decl.ref?.name ?? attr.decl.$refText;
return attrName === '@@map';
}

private isPrismaAttribute(attr: DataModelAttribute | DataFieldAttribute) {
if (!attr.decl.ref) {
return false;
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/orm/schemas/delegate/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export class SchemaType implements SchemaDef {
}
},
attributes: [
{ name: "@@index", args: [{ name: "fields", value: ExpressionUtils.array([ExpressionUtils.field("ownerId")]) }] },
{ name: "@@delegate", args: [{ name: "discriminator", value: ExpressionUtils.field("assetType") }] }
],
idFields: ["id"],
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/orm/schemas/delegate/schema.zmodel
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ model Asset {
comments Comment[]
assetType String

@@index([ownerId])

@@delegate(assetType)
}

Expand Down
4 changes: 2 additions & 2 deletions tests/regression/test/v2-migrated/issue-1243.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Regression for issue 1243', () => {
}
`;

await createTestClient(schema);
await createTestClient(schema, { usePrismaPush: true });
});

it('multiple id fields', async () => {
Expand All @@ -47,6 +47,6 @@ describe('Regression for issue 1243', () => {
}
`;

await createTestClient(schema);
await createTestClient(schema, { usePrismaPush: true });
});
});