环回:将模型关系保存到数据库

Loopback: saving model relations to database

我一直在阅读 Loopback 中的模型关系,但我不确定在持久化数据模型时如何保存关系。让我用下面的例子。

两个模型:类别文章

A Category has many Articles, which uses a foreign key categoryId 

假设有一个网页有一个 drop-down 类别列表,列表中每个类别的值是它们在数据库中的 auto-incremented Id。在 drop-down 列表下方,有一个输入字段和一个文本框,供您输入文章标题和正文 body。现在我的问题是:

当您点击保存按钮时,Article model 连同所选的 category Id 到 POST API 文章。我想知道您将如何保存 one-to-many 关系。您是检索类别 ID 的类别 object 并将其与文章 object 一起保存,还是仅将文章 object 与类别 ID 一起保存在 文章数据库table?

我有 Hibernate 的背景,但不确定如何在环回中正确使用关系。非常感谢回复,最好有一个例子。

编辑:好吧,这不是我问题的直接答案,但我发现这个 github 存储库对实现我正在寻找的东西非常有帮助,而且它提供了集成 angularJS 和环回作为后端的很好的例子。 在这里:https://github.com/beeman/loopback-angular-admin

我想要 post 我从 google 小组的 Líus Fontenelle Carneiro 那里得到的答案,以防将来有人同样的问题。

    Assuming you have Category hasMany Articles, Category endpoint will receive
by default a URL to handle the relation CRUD operations (e.g.
/categories/id/articles). When performing a POST to this URL, you're giving the
id that loopback will look for at the first place. If found, its id 
automatically fill related foreign key on Article nested model, together with
other fields you sent to fill Article properties.