orm - 为每个 followBy 用户在数组中创建记录
问题描述
我正在我的用户之间创建一个通知系统。我有以下架构:
model User {
id Int @id @default(autoincrement())
email String @unique
name String
user_name String @unique
password String
movies Movie[]
notifications Notification[]
followedBy User[] @relation("UserFollows", references: [id])
following User[] @relation("UserFollows", references: [id])
}
model Notification {
id Int @id @default(autoincrement())
link String?
movie_id Int?
message String
icon String?
thumbnail String?
user User @relation(fields: [userId], references: [id])
userId Int
watched Boolean
}
一个用户可以有多个FollowedBy
引用。
(我认为)需要的是Notification
在用户对象的记录中包含的每个用户对象上推送一条记录FollowedBy
。
createNotification: async (_, args, {req, res}) => {
const notification = await prisma.notification.create({
where: {
id: // loop through the current users FollowedBy records
},
data: {
// notification data
},
});
return notification;
},
解决方案
推荐阅读
- c# - 生存射击团结敌人不会受到伤害
- android - Dagger 2 Injector 并使用 IntKey 绑定 IntoMap
- php - 1X5矩阵树结构PHP数组
- node.js - 在NodeJS中检测一个数字是否可以被100整除
- python - 需要登录时使用 python 从 cloud.google.com 下载公共文件
- windows - 如何缩短 Git Bash 提示 (Windows)
- sql - 奇怪的 SQL 远程查询
- python - Python 子进程 - 在创建的新命令提示符中运行第二个命令
- swift - Firestore 收集侦听器大量读取
- php - 如何获取实例类名