next.js - 如何在两个表之间建立关系并进行有效查询?
问题描述
这是我的数据库架构:
model Logistics {
logisticsid String @id
logistics_store Int
logistics_date DateTime
Stores Stores? @relation(fields: [logistics_store], references: [storeid])
}
model Stores {
storeid Int @id
ka Int
country String
name String
city String
address String
kgrp_name String
password String
cxw Int
cx Int
plz Int
Logistics Logistics[]
}
这是我查询数据库并将结果发送回客户端的 API:
export default async function handle(req, res) {
await runMiddleware(req, res, cors);
try {
const logistics = await prisma.logistics.findMany({
where: { logistics_store: storeid },
include: { Stores }
});
res.json(logistics);
} catch (error) {
console.log(error);
}
}
我在这里想要实现的是获得Logistics
包含 3 个列的完整表格,并获得Stores
where logistics_store = storeid
。
解决方案
推荐阅读
- ios - Xcode 10 无效的二进制架构?
- azure - 我们可以将应用服务限制在 Azure 中的特定国家/地区吗?
- android - 在andoird的数字键盘中隐藏字母
- javascript - 如何使用 ApolloClient 记录 HTTP 请求和响应
- r - 在 R 中的自定义 DSL 中重新定义组
- excel - 通过 VBA 修改数据隐私级别
- matlab - 文本文件上的 readtable 忽略包含列名的第一行
- python - Pandas DataFrame:如何在滚动窗口上设置联合聚合
- security - 在端口 443 上部署时浏览器不提示输入客户端证书
- jcl - 将文件 1 与 12 文件合并,然后使用 jcl 将匹配的记录复制一个文件并取消匹配记录其他文件