“我想获取包含表的一些属性而不是使用 *,我现在的代码是这样的。
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 表用户的用户名和头像?
最佳答案
您应该能够通过 attributes 属性指定您想要返回的内容。我不确定您的架构是什么样的,所以我可能需要看起来有点不同,但这是我最好的猜测:
// If password, birth, and email are nested in the body:
{ attributes: ["body.username", "body.avatar", "id"],
...
那应该行得通。如果没有,请发布您的架构。
关于mysql - 关联表Sequelize js中获取自定义字段的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20646649/