“我想获得包含表格的一些属性而不是使用*,我现在的代码就是这个。
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);
}
);
});
这很好用,但是查询得到了一些我真正不需要的数据(密码,出生,电子邮件)我怎么才能获得,例如inlclude表User的用户名和头像?
答案 0 :(得分:1)
您应该可以通过attributes属性指定要返回的内容。我不确定你的架构是什么样的,所以我可能需要看起来有点不同,但这是我最好的猜测:
// If password, birth, and email are nested in the body:
{ attributes: ["body.username", "body.avatar", "id"],
...
那应该有用。如果没有,请发布您的架构。