我的应用程序有一个“类别”模型。
类别可以是其他类别的子类别。
所以有一个“CategoriesAssociations”模型。
这是代码:
/* api/models/Categories.js */
module.exports = {
attributes: {
name: {
type: "string"
},
parents: {
collection: "categoriesassociations",
via: "child"
},
children: {
collection: "categoriesassociations",
via: "parent"
}
}
}
/* api/models/CategoriesAssociations.js */
module.exports = {
attributes: {
parent: {
model: "categories"
},
child: {
model: "categories"
}
}
}
现在,当我使用find
又名路线时,/categories
我得到了这个:
[
{
"createdAt": "2015-08-24T14:16:46.662Z",
"updatedAt": "2015-08-24T14:24:23.819Z",
"name": null,
"id": "55db274e424996cc7e7512e2"
},
{
"createdAt": "2015-08-24T14:18:29.748Z",
"updatedAt": "2015-08-24T14:18:41.105Z",
"name": "test",
"id": "55db27b5424996cc7e7512e4"
}
]
所以没有parents
andchildren
属性的踪迹。
当我要求/categories/55db27b5424996cc7e7512e4/children
我得到这个时,确实在数据库中创建了关联:
[
{
"parent": "55db27b5424996cc7e7512e4",
"child": "55db274e424996cc7e7512e2",
"createdAt": "2015-08-24T14:32:43.429Z",
"updatedAt": "2015-08-24T14:32:43.429Z",
"id": "55db2b0bc97cc73083017f60"
}
]
Sails 文档指出,populate
蓝图的配置键定义:
蓝图控制器是否应该使用来自通过关联链接的其他模型的数据填充模型获取。如果您在一对多关联中有大量数据,则将其打开可能会导致非常繁重的 api 调用。
该值true
在我的项目中,但仍然没有填充关联属性。
我误解了文档还是我的项目有问题?
我使用帆 0.11.x