【问题标题】:Return additional fields from related model in StrongLoop从 StrongLoop 中的相关模型返回附加字段
【发布时间】:2016-11-18 18:19:37
【问题描述】:

在与Getting joined data from strongloop/loopback 类似的情况下,有 Products 和产品 Categories,如何返回 Category Name 而不是 id(外键)作为 /Products 的默认响应?我已经能够隐藏 id 字段但不返回名称。谢谢。

【问题讨论】:

  • 你的问题解决了吗?

标签: 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"}}}

希望这会有所帮助(尚未测试,但应该可以)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-29
    • 2021-06-13
    • 2015-09-02
    • 1970-01-01
    • 1970-01-01
    • 2018-09-05
    • 2011-01-19
    • 1970-01-01
    相关资源
    最近更新 更多