我需要 loopback framework 的帮助。 我有两个模型:Post和Media。 例子:
媒体
{
id: ObjectId("...a1"),
type: "gif",
path: "some/folder"
},
{
id: ObjectId("...a2"),
type: "mp4",
path: "some/folder"
},
发表
{
id: ObjectId("...b1"),
title: "Apollo 13",
content: [
{
mediaId: ObjectId("...a1"),
header: "header-1",
description: "descr-1"
},
{
mediaId: ObjectId("...a2"),
header: "header-2",
description: "descr-2"
}
]
},
{
id: ObjectId("...b2"),
title: "2 seconds to Moon",
content: [
{
mediaId: ObjectId("...a1"),
header: "header-3",
description: "descr-3"
},
]
}
你可以猜到我将使用MongoDb。我想描述这两种模型之间的关系,但不确定如何以正确的方式进行。
如果我只有mediaId
的数组,我会通过referenceMany
。现在它看起来更像embedsMany
,但嵌入了很多什么?
我甚至尝试制作类似MediaItem
模型的内容并为其提供transient
数据源。但我没有让它与其他API一起工作。
在最后,我希望获得一个或多个帖子,其中包含媒体数据,例如type
和path
字段。
有什么想法吗?
答案 0 :(得分:0)
您可能应该使用HasManyThrough关系(http://loopback.io/doc/en/lb2/HasManyThrough-relations.html),然后包含过滤器(http://loopback.io/doc/en/lb2/Include-filter.html)