【发布时间】:2015-10-22 14:47:49
【问题描述】:
我正在寻找一种使用 SequelizeJS 编写查询的方法,其中包含引用多个模型(表)的 OR 子句。
我希望 sql 最终看起来像这样:
select *
from Department
inner join Office on Department.OfficeId = Office.Id
where Office.Name like 'spokane%'
or Department.Name like 'spokane%'
我看到过关于过滤连接表的类似问题,答案如下所示。
options.include = [{
model: offices.model,
where: {
name: {
$like: 'spokane%'
}
}
}];
options.where = Sequelize.or(
{
'name': {
$like: 'spokane%'
}
});
departments.findAndCount(options);
但是这不会产生正确的 sql。
它会吐出这样的东西:
select *
from Department
inner join Office on Department.OfficeId = Office.Id and Office.name like 'spokane%'
where Department.name like 'spokane%'
任何帮助将不胜感激。
【问题讨论】:
标签: sequelize.js