eggjs / eggjs/egg

Sequelize query Or-ing where and include statements

Open
#5,162 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
19k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Description

### 在此输入你需要反馈的 Bug 具体信息(Bug in Detail):

https://stackoverflow.com/questions/49837932/sequelize-query-or-ing-where-and-include-statements
看一下这个文档,我想用 sequelize 做一样的查询操作但是看了半天文档也不清楚在egg.js里怎样来用。
我的 model 定义如下:
```
app.model.Blog.belongsTo(app.model.Relation, {
foreignKey: "userId",
targetKey: "followerId",
as: "follower",
});
```
查询时候的代码如下:
```
include: [
{
model: Relation,
as: "follower",
attributes: [],
},
],
where: {
[app.Sequelize.Op.or]: [
{
userId: userId,
},
{
"$follower.userId$": {
[app.Sequelize.Op.eq]: userId,
},
},
],
},
```
但是最终会报错 nodejs.SequelizeDatabaseError: Unknown column 'follower.userId' in 'where clause'
不清楚是不是写法不对,还是egg内部处理的问题呢,辛苦帮忙看看。

### 可复现问题的仓库地址(Reproduction Repo)

null

### Node 版本号:

v14.15.0

### Eggjs 版本号:

^2.6.1

### 相关插件名称与版本号(PlugIn and Name):

"egg-sequelize": "^6.0.0",

### 操作平台与版本号(Platform and Version):

MacBook Pro (13-inch, M1, 2020) 12.5.1

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.