首页 > 解决方案 > MySQL:在加入表时获取除一列之外的所有列

问题描述

我如何获取已加入用户表中除一列之外的所有列。

我希望password属性/列不会出现在 Promise 响应中。那是行不通的,因为我正在调用
attributes: { exclude: ['password'] } 哪个 DBTweet没有属性密码。加入的表DBUser有那个。

这是我目前的代码。我正在使用 Sequelize ORM

DBTweet.findAll({ include: [DBUser, DBComment], attributes: { exclude: ['password'] }})
.then(tweets => {
    res.status(200).json(tweets)
})
.catch(err => {
    printC(err)
    res.status(500).json({ error: err })
})

提前致谢

标签: javascriptnode.jsjoinsequelize.js

解决方案


那是我的解决方案:

DBTweet.findAll({ include: [{ model: DBUser, attributes: { exclude: ['password'] } }, DBComment]})

推荐阅读