![](/img/trans.png)
[英]filter Sequelize belongsToMany get<Association> association table
[英]How to get custom fields in association table 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);
}
);
});
这工作正常,但查询得到一些我真的不需要的数据(密码,出生,电子邮件)我怎么才能得到,例如inlclude表用户的用户名和头像?
您应该能够通过attributes属性指定要返回的内容。 我不确定你的架构是什么样的,所以我可能需要看起来有点不同,但这是我最好的猜测:
// If password, birth, and email are nested in the body:
{ attributes: ["body.username", "body.avatar", "id"],
...
这应该工作。 如果没有,请发布您的架构。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.