egg Sequelize query Or-ing where and include statements

vx6bjr1n  于 5个月前  发布在  其他
关注(0)|答案(1)|浏览(66)

在此输入你需要反馈的 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

j9per5c4

j9per5c41#

egg-sequelize其实只是封装了sequelize库,把sequelize一些对象挂载到egg对应对象中,使得egg使用起来sequelize更方便而已,具体sql语句的语法建议去参考sequelize的文档

相关问题