Mysql 如何在关联表Sequelize js中获取自定义字段

Mysql 如何在关联表Sequelize js中获取自定义字段,mysql,node.js,orm,sequelize.js,Mysql,Node.js,Orm,Sequelize.js,“我想获得include表的一些属性,而不是使用*,我现在的代码是这样的 module.exports = function(app){ app.get('/post', function(req, res){ model.Post.findAll( { attributes: ["body", "id"], {include: [model.User]).success(function(rows){

“我想获得include表的一些属性,而不是使用*,我现在的代码是这样的

module.exports = function(app){
    app.get('/post', function(req, res){
        model.Post.findAll(
            { attributes: ["body", "id"],
            {include: [model.User]).success(function(rows){
                    res.json(rows);
            }

        );


    });

这很好,但是查询得到一些我确实不需要的数据(密码、出生、电子邮件)我如何才能仅获取,例如,Include表用户的用户名和头像?

您应该能够通过attributes属性指定想要返回的内容。我不确定您的模式是什么样子,因此我可能需要看起来有点不同,但这里是我的最佳猜测:

// If password, birth, and email are nested in the body:
{ attributes: ["body.username", "body.avatar", "id"],
...

那应该行。如果不行,请发布你的模式。

你是说
{attributes:[“body”、[“username”、“avatar”]、“id”],…
?我不确定我的语法是否正确,但你如何理解它,它将返回
body
id
,并将
username
属性重命名为
avatar
。我只知道你答案中的代码在第二个冒号处有语法错误。抱歉,但你的答案仍然不正确。正确的答案在这里: