【发布时间】:2016-08-09 02:39:51
【问题描述】:
我正在尝试深度填充集合。
例如
// UnitType.js
name: { type: 'string' }
// Unit.js
unitType: {
model: 'unitType',
via: '_id',
required: true,
index: true
}
// Product.js
unit: {
model: 'unit',
via: '_id',
required: true,
index: true
},
问题是,据我所知,我从互联网研究中了解到,像
Product.find().populate('unit.unitType');
目前在 Sails 中不受支持。为了达到我目前想要的结果
- 查询产品填充
unit - 使用 `product.unit.unitType`` 的 id 查询 UnitTypes
-
.map()product.unit.unitType回复
这当然远非理想。我还尝试在模型中使用toJSON 来“预填充”unitType -> 不起作用,因为它不支持 Promises。
关于这个问题,so 和 PR 在 github 上有很多线程,但到目前为止我还没有找到解决这个问题的方法。有什么办法可以改善吗?
【问题讨论】:
-
如果您在工作流程中使用 async/await 或生成器(可能没有),您可以使用我的 gist(将其编译为 js)并将其合并到您的模型中,不过它只是一个 WIP.. .gist.github.com/Zaggen/7de61775ed083d10c07e