环回数据反规范化

Loopback data denormalization

我有 2 个模型。一个是Article (content, category),另一个是Category (id, name)

我在文章中定义了与类别的关系。

"categories": {
  "type": "hasOne",
  "model": "Category",
  "foreignKey": "category"
}

我在类别字段中插入带有类别 ID 的新产品。

现在,当我通过 REST API 获取文章时,我希望收到类别名称而不是类别 ID。 我想根据 documentation 来计算,但失败了。

我使用 MySQL 关系数据库。

我怎样才能做到这一点?

您需要使用包含过滤器 https://docs.strongloop.com/display/public/LB/Include+filter

你的情况:

/articles?filter[include]=categories