modelUser { id Int@id@default(autoincrement()) profile Profile?}modelProfile { id Int@id@default(autoincrement()) user User @relation(fields: [userId], references: [id]) userId Int@unique// relation scalar field (used in the `@relation` attribute above)}
在飞布中可以得到对应的ER图,如下:
在关系型数据库中可以定义多个字段的一对一关联:
modelUser { firstName String lastName String profile Profile?@@id([firstName, lastName])}modelProfile {id Int@id@default(autoincrement())user User @relation(fields: [userFirstName, userLastName], references: [firstName, lastName])userFirstName String// relation scalar field (used in the `@relation` attribute above)userLastName String// relation scalar field (used in the `@relation` attribute above)@@unique([userFirstName, userLastName])}
modelUser { id Int@id@default(autoincrement()) posts Post[]}modelPost { id Int@id@default(autoincrement()) author User @relation(fields: [authorId], references: [id]) authorId Int}
在飞布中可以得到对应的ER图,如下:
在关系型数据库中可以定义多个字段的一对多关联:
modelUser { firstName String lastName String post Post[]@@id([firstName, lastName])}modelPost { id Int@id@default(autoincrement()) author User @relation(fields: [authorFirstName, authorLastName], references: [firstName, lastName]) authorFirstName String// relation scalar field (used in the `@relation` attribute above) authorLastName String// relation scalar field (used in the `@relation` attribute above)}
modelPost { id Int@id@default(autoincrement()) title String categories CategoriesOnPosts[]}modelCategory { id Int@id@default(autoincrement()) name String posts CategoriesOnPosts[]}modelCategoriesOnPosts { post Post @relation(fields: [postId], references: [id]) postId Int// relation scalar field (used in the `@relation` attribute above) category Category @relation(fields: [categoryId], references: [id]) categoryId Int// relation scalar field (used in the `@relation` attribute above) assignedAt DateTime@default(now()) assignedBy String@@id([postId, categoryId])}