P
Prisma7mo ago
badis

can i pass a model to a type, the same way i pass a type to a model in prisma schema ?

i have a one to one relation in prisma schema and i want to switch it with a type instead of creating a new model, but currently i don't know if i can feed the type something other then string number ...
Solution:
Unfortunately this isn’t directly possible in the ORM. We have some suggestions: https://www.prisma.io/docs/orm/prisma-schema/data-model/table-inheritance
Table inheritance | Prisma Documentation
Learn about the use cases and patterns for table inheritance in Prisma ORM that enable usage of union types or polymorphic structures in your application.
Jump to solution
8 Replies
jonfanz
jonfanz7mo ago
Could you post your schema? Both what you have right now and what you would like to see
badis
badisOP7mo ago
here is the portion where i'm struggling , the Product is a model while the productSection is a type
jonfanz
jonfanz7mo ago
What is ProductsSection related to? (besides Product)
badis
badisOP7mo ago
productSection will be added to section , so that i can say section can be sectionA or sectionB ... i started working this out using models as you see the relation between section and sectionCarousel , but i want to change the different sections A B C to types because the relation is one to one anyway so i don't need a model in the screenshot you can see sectoinCarousel as a model and productsSection as a type , i'm trying to turn them all to types and feed them to Section as optional , so that the Section can be CarouselSection or ProductSection is this clear ?
jonfanz
jonfanz7mo ago
Ah, I see. So you’re saying that a Section can have one of a SectionCarousel, ProductsSection, etc. is that right?
badis
badisOP7mo ago
yes and because its a one to one relationship , i would prefere to use type instead of creating some models
Solution
jonfanz
jonfanz7mo ago
Unfortunately this isn’t directly possible in the ORM. We have some suggestions: https://www.prisma.io/docs/orm/prisma-schema/data-model/table-inheritance
Table inheritance | Prisma Documentation
Learn about the use cases and patterns for table inheritance in Prisma ORM that enable usage of union types or polymorphic structures in your application.
jonfanz
jonfanz7mo ago
You could also investigate putting this data in something like a JSON field. There are pros and cons
Want results from more Discord servers?
Add your server