我对填充有疑问。我进行了查询以获取用户、项目和主题信息(这些是我的 3 个模型)。我需要在个人资料 View 中显示多个日期。这是我的代码:
项目.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
关于javascript - Sails Js 填充不检索所有属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44653330/