model with pre-defined sub-model
Ciao, let assume i want to create a list of sub-model to use inside the model. is it possible?
exampe
model LogInfo{
insTS DateTime? @default(now())
updTS DateTime? @updatedAt
idUserIns String? @default("")
idUserUpd String? @default("")
}
model Product extends LogInfo{
id String @id @default(uuid())
productName String? @default("")
logo String? @default("")
}
}
1 Reply
You've gone full bot mode! Let me fetch that AI answer for you ASAP.
Currently, Prisma does not natively support model inheritance or the ability to define a "sub-model" (like your LogInfo) and extend it in other models directly in the Prisma schema. This means you cannot write something like model Product extends LogInfo in your schema.prisma file and have Prisma automatically include the fields from LogInfo in Product.
This feature—model inheritance or reusable field collections—has been a long-standing request in the Prisma community, with many users expressing the need to avoid repetitive code for common fields across models. There are several proposals and discussions about supporting abstract models, fragments, or mixins, but as of now, this is not available in Prisma itself. You must manually copy the fields into each model that needs them Reuse collections of fields inside models, Allow for model inheritance, to reduce repetitive code.
Workarounds:
- You can use community tools like ZenStack, which adds model inheritance on top of Prisma. With ZenStack, you can define abstract models and extend them, and it will generate the appropriate Prisma schema for you Abstract Model for common fields.
- Other tools like
prisma-compositor or prisma-util offer schema pre-processing to allow fragments or reusable field blocks, but these are not official Prisma features.
Example (not supported natively):
You must instead do:
In summary: Prisma does not support sub-models or inheritance natively. You need to copy fields or use a third-party tool for this functionality.
✅ Great, thanks for letting us know that this solved your question!