我有2个型号。一个是Article (content, category)
,另一个是Category (id, name)
。
在第一条中我已经定义了与类别的关系。
"categories": {
"type": "hasOne",
"model": "Category",
"foreignKey": "category"
}
我在类别字段中插入带有类别ID的新产品。
现在,当我通过REST API获取文章时,我希望收到类别名称而不是类别ID。 我想根据documentation计算出来,但失败了。
我使用MySQL关系数据库。
我怎样才能做到这一点?
答案 0 :(得分:0)
您需要使用包含过滤器 https://docs.strongloop.com/display/public/LB/Include+filter
在你的情况下:
/articles?filter[include]=categories