2013-12-17 108 views
3

“我想要得到的一些属性包括,而不是使用*表,我的代码,现在是这样的。在关联表如何获得自定义字段Sequelize JS

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); 
      } 

     ); 


    }); 

这工作得很好,但查询获取一些我真正不需要的数据(密码,出生地址,电子邮件地址)我怎样才能得到,例如用户名和用户名头像?

回答

0

你应该能够指定你想要通过属性属性我不确定你的模式是什么样的,所以我可能需要看起来有点不同,但这是我的最佳猜测:

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

这应该工作。如果没有,请发布您的架构。

+0

你是不是指'{attributes:[“body”,[“username”,“avatar”],“id”],...'? – borisdiakur

+0

我不确定我的语法是否正确,但是如何获得它,它会返回'body','id',并将'username'属性重命名为'avatar'。 – EmptyArsenal

+0

我唯一知道的是答案中的代码在第二个冒号中有语法错误。 – borisdiakur

相关问题