[英]Sails Js populate don't retrieve all attributes
我有人口問題。 我進行了查詢以獲取用戶、項目和主題信息(這些是我的 3 個模型)。 我需要在個人資料視圖中顯示多個日期。 這是我的代碼:
項目.js:
module.exports = {
attributes: {
name: {
type: "string"
},
topics: {
collection: "topic",
via: "projects"
},
members: {
collection: "user",
via: "projects"
},
content: {
collection: "content",
via: "projectData"
}
}
};
主題.js:
module.exports = {
attributes: {
name: {
type: "string"
},
projects: {
collection: "project",
via: "topics"
}
}
};
在 User.js 中:
show: function(req, res, next) {
User.findOne({id: req.session.User.id}).populateAll().exec(function prjFound(err, user){
if (err) return next(err);
if (!user) return next();
console.log(user);
res.view({
user: user
});
});
},
控制台打印:
{ projects:
[ { name: 'Fran',
createdAt: '2017-06-19T21:33:17.152Z',
updatedAt: '2017-06-19T21:33:17.190Z',
id: 97 },
{ name: 'River Plate',
createdAt: '2017-06-19T21:36:38.757Z',
updatedAt: '2017-06-19T21:36:38.798Z',
id: 98 },
{ name: 'Guido',
createdAt: '2017-06-20T01:33:53.843Z',
updatedAt: '2017-06-20T01:33:53.926Z',
id: 99 } ],
group: [],
mat: 222222,
name: 'Francisco',
lastname: 'P',
email: 'fran@1.com.ar',
encryptedPassword: '$2a$10$nKp/eAOCDPw4BS.PvQCThe42wa2/8ZABw4JzA0no9GPVT4VjFl3ZO',
createdAt: '2017-06-19T21:32:10.535Z',
updatedAt: '2017-06-19T21:32:10.535Z',
id: '594842da6aeecd880ebab4e6'
}
我想獲得項目模型的所有屬性(內容、主題和成員),而不僅僅是名稱和 ID。
任何人都可以解釋為什么我的代碼是錯誤的?
Sails/Waterline populate
/ populateAll
做 1 級人口。 對於 2 級或更深層次,您需要為它編寫代碼。
例如,收集用戶項目的 id 並在Project.find
上執行populateAll
Sailsjs 目前不支持填充字段內的填充。 在返回的響應中編寫查詢並將其附加到您要填充的字段,發送帶有您想要的結果的響應。
檢查這個。
let result = await model.find(filter).populate("fieldName", {select:['attribute1','attribute1']})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.