【问题标题】:Return additional fields from related model in StrongLoop从 StrongLoop 中的相关模型返回附加字段
【发布时间】:2016-11-18 18:19:37
【问题描述】:
【问题讨论】:
标签:
node.js
loopbackjs
strongloop
【解决方案1】:
假设您有关系Product hasOne Category,称为productCat
使用节点 API
Product.find({
include: {
relation: 'productCat', // include the Category object
scope: { // further filter the Category object
fields: 'name', // only show category name
}
}
}, function(err, results) { /* ... */});
使用 REST API
GET api/Products?filter={"include":{"relation":"productCat","scope":{"fields":"name"}}}
希望这会有所帮助(尚未测试,但应该可以)