我正在将我的LoopBack 3应用迁移到LoopBack 4。在lb3应用中,我在我的模型中使用了embeds one和embeds many功能,但是在lb4中找不到相同的关系。根据文档,它还没有被实现。是文档过时了还是没有了?有什么解决方法吗?
没有, EmbedsOne
和 EmbedsMany
关系目前还没有实现。目前的重点是实现和改进SQL关系。
一个变通的办法是使用 HasOne
和 HasMany
关系。但是,它并没有得到StrongLoop的官方支持。
当你尝试添加时,它无法在关系中看到。但在这个问题中,他们估计已经修复了。https:/github.comstronglooploopback-nextissues2130。
下面是使用实例。
@model()
export ExampleMainClass extends Entity{
@property({
type: 'string',
id: true,
generated: true,
})
id: string;
@property()
key: ExampleSubClass;
}
@model()
class ExampleSubClass{
@property({
type: 'string',
id: true,
generated: true,
})
id: string;
@property({
type: 'string',
required: true,
})
name: string;
}
创建一个模型,然后在这个模型类里面写上你的子模块。并把它作为一个属性添加到你的主模块中。然后就可以了。