🌐
Stack Overflow
stackoverflow.com › questions › 76677706 › prisma-how-can-i-use-base-entitymodel
radix - Prisma / How can i use base entity(model)? - Stack Overflow
model Test1 { id Int @id name String @db.VarChar(30) base Base } model Test2{ id Int @id name String @db.VarchAr(30) base Base } model Base { reg_id String @db.Char(12) reg_dt DateTime @default(now()) @db.DateTime(6) edit_id String @db.Char(12) edit_dt DateTime @updatedAt @db.DateTime(6) } ... Unfortunately, this feature is not currently supported in Prisma.
🌐
GitHub
github.com › prisma › prisma › discussions › 23222
Creating a base class for models · prisma/prisma · Discussion #23222
I'm trying to create a base class to create basic and recurrent requests to the models that can be extended. The issue that comes up is somewhat recurrent in the issues section, but none of the proposed solutions worked for my case. ... type ModelName = keyof typeof Prisma.ModelName export class BaseModel<T extends ModelName> { protected model: PrismaClient[T] constructor(modelName: T) { this.model = db[modelName] } findUnique = <Args = Prisma.Args<T, 'findUnique'>, Result = Prisma.Result<T, Args, 'findUnique'>>( args: Args, ): Result => this.model.findUnique(args) findMany = <Args = Prisma.Ar
Author   prisma
Discussions

Allow for model inheritance, to reduce repetitive code.
This repeats for a lot of models, which makes the schema.prisma file needlessly verbose. I would be fantastic to define some sort of base model from which DB models could extend from. More on github.com
🌐 github.com
11
March 31, 2022
typescript - Get base model types on client with Prisma and NextJS - Stack Overflow
Prisma makes a namespace available that has a ton of useful types for the different api methods. However, I can't find one for just the base models. For instance, I have the following model: model More on stackoverflow.com
🌐 stackoverflow.com
March 15, 2023
Is there a way to create abstract models in prisma ORM?
I would like to define these all fields in one abstract base model and then extend all other models using that base model so that the repetitive code can be avoided and the risk of missing to add those fields in newer models will be lowered. I tried to find the solution in prisma doc but I'm ... More on stackoverflow.com
🌐 stackoverflow.com
Possibility to merge & extend prisma models ?
As there is most likely a parser for .prisma files (See #92) coming soon, it would be nice to have the possibility to merge & extend existing models, like: post.prisma model Post { title String @pg... More on github.com
🌐 github.com
11
January 8, 2020
🌐
Prisma
prisma.io › home › overview of prisma schema › overview of prisma schema › overview of prisma schema
Prisma schema | Prisma Documentation
It is typically called schema.prisma ... and data model · The Prisma Schema (or schema for short) is the main method of configuration for your Prisma ORM setup. It consists of the following parts: Data sources: Specify the details of the data ...
🌐
Prisma
prisma.io › home › models › models › models › models
Models | Prisma Documentation
December 19, 2022 - The data model definition part of the Prisma schema defines your application models (also called Prisma models).
🌐
Medium
medium.com › @enayetflweb › understanding-prisma-models-a-beginners-guide-with-examples-2927b2ade2aa
Understanding Prisma Models: A Beginner’s Guide with Examples | by Md Enayetur Rahman | Medium
October 25, 2024 - Prisma models are at the core of ... If you’re new to Prisma, think of models as representations of database tables, where each model field translates to a table column....
🌐
GitHub
github.com › prisma › prisma › issues › 12604
Allow for model inheritance, to reduce repetitive code. · Issue #12604 · prisma/prisma
March 31, 2022 - private model BaseModel { id String @id @default(uuid()) createdAt DateTime @default(now()) updatedAt DateTime @default(now()) @updatedAt } model User extends BaseModel { displayName String ...
Author   prisma
🌐
Prisma Client Python
prisma-client-py.readthedocs.io › en › stable › reference › model-actions
Model Based Access - Prisma Client Python
from prisma import Prisma, register def get_client() -> Prisma: return Prisma() register(get_client) All query operations are the exact same as with client-based access. Converting client-based access operations to model-based access operations simply requires changing calls like: db.user to User.prisma().
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 75739754 › get-base-model-types-on-client-with-prisma-and-nextjs
typescript - Get base model types on client with Prisma and NextJS - Stack Overflow
March 15, 2023 - With all the generated types Prisma offers, I'd expect there to be a generated Instruction type available for the client that automatically updates when i change my schema that would be something like: // basically just an exact reflection of the model interface Instruction { id: string; order: string; description: string; ...etc }
🌐
Prisma
prisma.io › home › prisma orm
What is Prisma ORM? (Overview) | Prisma Documentation
November 3, 2020 - datasource db { provider = "postgresql" } generator client { provider = "prisma-client" output = "./generated" } model User { id Int @id @default(autoincrement()) email String @unique name String? posts Post[] } model Post { id Int @id @default(autoincrement()) title String published Boolean @default(false) author User?
🌐
3D Warehouse
3dwarehouse.sketchup.com › model › ubcb863aa-c943-41e2-964b-bed60da7de2e › Prisma-de-base-rectangular
3D Warehouse
April 30, 2014 - 3D Warehouse is a website of searchable, pre-made 3D models that works seamlessly with SketchUp.
🌐
Basedash
basedash.com › home › blog › how to model inheritance in prisma
How to model inheritance in Prisma | Basedash
March 29, 2022 - The Prisma example uses UUIDs for the models, but at Basedash, we use consecutive integers. So we first create the parent, await its creation to get its id and then create the child with that very id.
Top answer
1 of 2
1

In short: No there is such thing as abstract models or inheritance in general implemented in Prisma as of now.

However there is an open Github issue proposal which describes how interfaces could be used for that kind of abstraction. https://github.com/prisma/prisma/issues/2506. Unfortunately there hasn't been made any real progress on the issue since 2020.


Thus people started to implement it by themselves. A custom library called ZenStack built on top of Prisma offers abstract models. You can define .zmodel model files which are compiled to the normal prisma.schema.

An example from the ZenStack documentation:

abstract model Basic {
    id String @id
    createdAt DateTime @default(now())
    updatedAt DateTime @updatedAt
}

model User extends Basic {
    name String 
}

The generated prisma file only contains one User model:

model User {
    id String @id
    createdAt DateTime @default(now())
    updatedAt DateTime @updatedAt
    name String @id
}
2 of 2
0

Prisma ORM does not have the concept of "abstract models" in the same way Django ORM does. In Django, an abstract model serves as a base class for other models but does not produce a database table of its own. Instead, its fields are added to the child models that inherit from it.

In Prisma, you can't define a model that is only used for inheritance purposes. However, there are certain approaches you can take to emulate abstract-like behavior:

Using Generators or Scripts:

You could set up a generator or a script to produce the final schema.prisma file by combining shared fields and model-specific fields. This is a more involved setup but can help maintain DRYness if you have a lot of shared fields.

Model Relations instead of Inheritance:

Consider if a relation between models might serve better than inheritance. For instance, if there's a shared set of attributes across multiple models, those attributes could be refactored into their own model, and a relation could be established.

model Profile {
  id      Int    @id @default(autoincrement())
  name    String
  email   String @unique
  user    User?  @relation(fields: [userId], references: [id])
  userId  Int?
  admin   Admin? @relation(fields: [adminId], references: [id])
  adminId Int?
}

model User {
  id      Int      @id @default(autoincrement())
  profile Profile  @relation(fields: [profileId], references: [id])
  profileId Int
  // ... other specific fields ...
}

model Admin {
  id      Int      @id @default(autoincrement())
  profile Profile  @relation(fields: [profileId], references: [id])
  profileId Int
  // ... other specific fields ...
}

In this example, the Profile model holds fields common to both User and Admin.

🌐
GitHub
github.com › prisma › prisma › issues › 1291
Possibility to merge & extend prisma models ? · Issue #1291 · prisma/prisma
January 8, 2020 - import "dependency/prisma/core.prisma" extend model Post { title String @pg.varchar(50) slug String }
Author   prisma
🌐
Sketchfab
sketchfab.com › tags › prisma
Prisma 3D models - Sketchfab
Prisma 3D models ready to view and download for free.
🌐
3D Warehouse
3dwarehouse.sketchup.com › model › db8f81b1-f4e6-49c6-be0a-1570ca3016c4 › prisma-base-cuadrada-sargento-molamaz
prisma base cuadrada sargento molamaz - Model
February 28, 2024 - 3D Warehouse is a website of searchable, pre-made 3D models that works seamlessly with SketchUp.
🌐
DEV Community
dev.to › denispixi › prisma-un-toolkit-para-bases-de-datos-orm-para-typescript-y-node-js-3g9
Prisma, un toolkit para bases de datos (¿ORM?) para TypeScript y Node.js - DEV Community
May 8, 2020 - Reemplaza los ORM tradicionales y facilita el acceso a la base de datos con un generador de consultas o query builder automáticamente generado y type-safe que se adapta a nuestro esquema de base de datos. Se compone principalmente de las siguientes partes: Prisma Client: generador de consultas, autogenerado y seguro para Node.js y TypeScript · Prisma Migrate (experimental): sistema de migración y modelado de datos declarativos
🌐
PRISMA statement
prisma-statement.org
PRISMA statement
PRISMA (Preferred Reporting Items for Systematic reviews and Meta-Analyses) is a guideline designed to improve the reporting of systematic reviews. PRISMA provides authors with guidance and examples of how to completely report why a systematic ...