【发布时间】:2019-10-10 17:38:33
【问题描述】:
我必须尝试使用 sequelize npm 包将我的 postgre sql 查询转换为 orm 概念,请指导我。
select * from "locationDepartmentMappings" as a
inner join "departments" as b on a."departmentId" = b.id
inner join "locations" as c on a."locationId" = c.id
where (
b."departmentName" like '%Accounting%' or c."locationName" like '%Accounting%'
)
limit 1;
按照下面的代码,我仍然得到了
错误:列 locationDepartmentMapping.department.departmentName 不存在
正如@shivam 提到的,我已经尝试过取决于我的下面,你能不能我需要改变什么,
let ldv = await LocationDepartmentModel.findAll({
include: [
{
model: LocationModel,
as: "location",
required: true,
},
{
model: DepartmentModel,
as: "department",
required: true,
}
],
where: {
$or: [
{
"department.departmentName": { like: `%${reqQueryName}%` }
},
{ "location.locationName": { like: `%${reqQueryName}%` } }
]
},
limit:1
});
【问题讨论】:
-
你已经定义了你的模型了吗?如果是这样,请将其包含在问题中。
-
@TheWildHealer,是的,已创建。 [link]docs.sequelizejs.com,你要查吗?
-
@TheWildHealer,感谢您指出连接错误。
标签: node.js postgresql npm sequelize.js