How can I assign some tags to the post using Prisma.js?
I have some tags already and I want to assign some tags to the post? I don't want to create a new tag.
schema.prisma:
model Post {
Id String @id @default(uuid())
AuthorId String
Author User @relation(fields: [AuthorId], references: [Id])
CategoryId String?
Category Category? @relation(fields: [CategoryId], references: [Id])
Title String @db.VarChar(255)
Description String? @db.MediumText
Summary String? @db.VarChar(255)
Tags TagPostMapping[]
}
model TagPostMapping {
Id String @id @default(uuid())
Post Post? @relation(fields: [PostId], references: [Id])
PostId String?
Tag Tag? @relation(fields: [TagId], references: [Id])
TagId String?
CreatedDate DateTime @default(now())
ModifiedDate DateTime? @updatedAt
}
model Tag {
Id String @id @default(uuid())
Title String @unique
Posts TagPostMapping[]
CreatedDate DateTime @default(now())
ModifiedDate DateTime? @updatedAt
}
In the Prisma website, there is an example but it's suitable for creating some tags and assign them to the Post. While I want to add some of the existing tags to the article.