orm - Sequelize,我如何从多个表中找到
问题描述
我正在使用 Sequelize 从多个表中进行选择,目前正在寻找一种在 E.tmpField 上包含约束的方法,下面的示例不起作用...
await A.findOne({
include: [
{
model: B,
include: [
{
model: C,
include: [D, E],
},
],
},
{
model: F,
include: [G],
},
],
where: {
name: { [Op.in]: nameList },
$and: [{ '$E.tmpField$': 100 }],
},
});
解决方案
您可以为每个预先加载的模型指定 where 选项:
await A.findOne({
where: {
name: { [Op.in]: nameList } // Where option for model A
},
include: [
{
model: B,
include: [
{
model: C,
include: [
{
model: D
},
{
model: E,
where: {
tmpField: 100 // Where option for model E
}
}
],
},
],
},
{
model: F,
include: [G],
},
]
});
推荐阅读
- reactjs - 如何在悬停时为图表图例符号设置动画?
- amazon-cloudformation - 在 Cloudformation 中使用 AWS Secrets manager 的 Secret
- python - 将 sphinx 模块导入 python
- php - PHP CURL 响应返回编码字符
- tableau-api - 你如何让前 30 个最大的气泡出现在气泡图中?
- ios - 找到 NativeScript iOS 元数据,但符号在运行时不可用
- python - 在 Keras 中定义自定义 LSTM 单元?
- python - i(ContentsOwner, MCN) 在哪里可以找到 Youtube 报告 API 中的 Finalized Red(Premium)&Superchat 收入数据?
- excel - 如何使用 vba 将同一目录中的文件复制到另一个目录?
- spring - Spring Conditional SpEL 无法解析