[英]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.