node.js - Prisma - 在更多条件下更新一个资源
问题描述
我想知道是否可以在多种情况下更新资源。例如,考虑以下两个表:
+----------+----------+
| Table1 | Table2 |
+----------+----------+
| id | id |
| param1T1 | param1T2 |
| param2T1 | param2T2 |
| idTable2 | |
+----------+----------+
我想将记录更新到表Table1
中,我知道该字段id
是primary key
AND,其中idTable2
具有特定值。
使用该.update()
方法我在编译时出错,但我不明白为什么我不能使用更多条件更新单个标识。这是我的更新:
table1.update({
where: {
AND: [
{ id: 1 },
{ Table2: { id: 1 } }
]
},
data: toUpdate
});
现在,我.updateMany()
改用.update()
. 有解决方案还是不可能?
解决方案
AND
真的没有必要。根据您的架构,您可以尝试以下操作:
await prisma.table1.update({
where: {
// the AND condition is implicit. Update only happens when both of the conditions provided hold true.
id: 1,
idTable2: 1
},
data: toUpdate,
});
推荐阅读
- javascript - 已部署的 iOS React Native 应用程序中的空白图像
- reactjs - React 中的 Axios GET 请求
- python - 我怎样才能使它更有效率?Python DNA 生成器
- ruby-on-rails - rspec 期望会根据现有的其他期望而变化
- php - LOCK TABLES 会导致 InnoDB 中的死锁吗?
- javascript - 热门在 Meteor 中为自定义域上的 Graphlql 请求设置 HTTP 标头
- html - 如何让我的激活表单与相对位置一起使用?
- reactjs - reduce(prev,curr)函数在react redux中返回未定义
- powershell - 导出完整的 TFS 工作项,包括。PowerShell 的历史
- r - 如何通过变量查找最新数据