dav*_*ron 3 node.js sails.js waterline
我最近开始在sailsJs 上开发并且不理解其中的微妙之处请向我解释SailsJs 中的填充内容,谁能做简单的例子提前谢谢?是什么?
User.find({ name: 'foo' })
.populate('pets', { name: 'fluffy' })
.exec(function(err, users) {
if(err) return res.serverError(err);
res.json(users);
});
Run Code Online (Sandbox Code Playgroud)
populate 用于关联。当你的模型是这样的:
// User.js
module.exports = {
attributes: {
name: {
type: "string"
},
pet: {
model: "pet"
}
}
}
Run Code Online (Sandbox Code Playgroud)
这里用户集合的 pet 属性是对 pet 表的引用。在用户表中,它将只存储宠物的 id 列。但是,当您在查找时进行填充时,它将获取宠物条目的整个记录并将其显示在此处。这仅适用于一对一关联。您可以拥有多对一关联以及多对多关联。有关更多详细信息,请参阅此文档
| 归档时间: |
|
| 查看次数: |
854 次 |
| 最近记录: |