sql - Node.js Sequelize findAll() 包含表模型的列

标签 sql node.js sequelize.js

我正在尝试在两个表之间的合并表中搜索以下条件。

它应该收集并返回具有买方 'alex' 或卖方 'alex' 的记录。
买方存在于 Chat 表中,卖方存在于 Market 表中,我包括如下所示。但是,我无法让它工作。欢迎任何想法。

Chat.findAll({
        where: {
           buyer: 'alex',
               seller: 'alex'

          },
        include: [{
          model: Market,
          required: true
         }]
      })

最佳答案

seller 必须在 Market

Chat.findAll({
        where: {
           buyer: 'alex',
          },
        include: [{
          model: Market,
          required: true,
          where: {
            seller: 'alex'
          }
        }]
      })

关于sql - Node.js Sequelize findAll() 包含表模型的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51000931/

相关文章:

sql - 将一个表中的值更新到另一个表中

一张表有三个标识符的SQL算法

MySQL 连接,ORDER BY RAND() 然后排序 ASC(最好使用 Sequelize)

node.js - 如何在特定目录中安装 npm 包

node.js - 在 Sequelize.js 中使用关联实现数据库规范化

sql - 如何在 SQL Developer 中将 .sql 文件作为包文件打开?

mysql - 包含 MySQL 查询结果中未找到的值

string - 从nodejs中的字符串调用函数

node.js - 使用 Sequelize 如何获得最接近该对象半径内的纬度和经度的 n 个元素?

node.js - Node and sequelize -> .catch(...) 没有按预期工作