[英]i'm using nest js and mongodb with prisma and i want to add three collection in how can i do?
i want to add three model of prisma just like.我想添加三个 model 的 prisma 就像。 schema.prisma
模式.prisma
model women{
id string @id @default(auto()) @map("_id") @db.ObjectId
womenname: string;
womengender: string
womendob: string
womenincome: string
}
model men{
id string @id @default(auto()) @map("_id") @db.ObjectId
malename: string;
malegender: string
maledob: string
maleincome: string
}
model child{
id string @id @default(auto()) @map("_id") @db.ObjectId
childname: string;
childgender: string
childdob: string
}
how can i add this three model in one model. just Like this.我如何将这三个 model 添加到一个 model 中。就像这样。
model information{
male: //male model data,
women: // women model data,
child: //child model data
}
That's already described in the documentation of Prisma, you have two options Prisma 的文档中已经对此进行了描述,您有两种选择
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
tasks Task[]
}
model Task {
id String @id @default(auto()) @map("_id") @db.ObjectId
user Product @relation(fields: [userId], references: [id])
userId String @db.ObjectId
}
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
tasks Task[]
}
// This will not be a different collection but it will work as "rules" or schema for the attributes inside the user.tasks property
type Task {
title String
description String
}
With this last example you will have something like this使用最后一个示例,您将拥有类似的东西
// users document
{
"_id": "SOME RANDOM ID",
"tasks": [
{
"title": "SOME TITLE",
"description": "SOME DESCRIPTION"
}
]
}
You can also try to take a deeper look at the documentation here https://www.prisma.io/docs/concepts/components/prisma-client/composite-types您也可以尝试在此处更深入地查看文档https://www.prisma.io/docs/concepts/components/prisma-client/composite-types
I hope it has been helpful.我希望它有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.