Loopback 4 有 embeds one 和 embeds many 的关系吗?

问题描述 投票:0回答:1

我正在将我的LoopBack 3应用迁移到LoopBack 4。在lb3应用中,我在我的模型中使用了embeds one和embeds many功能,但是在lb4中找不到相同的关系。根据文档,它还没有被实现。是文档过时了还是没有了?有什么解决方法吗?

loopbackjs loopback4
1个回答
0
投票

没有, EmbedsOneEmbedsMany 关系目前还没有实现。目前的重点是实现和改进SQL关系。

一个变通的办法是使用 HasOneHasMany 关系。但是,它并没有得到StrongLoop的官方支持。


0
投票

当你尝试添加时,它无法在关系中看到。但在这个问题中,他们估计已经修复了。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;

}

创建一个模型,然后在这个模型类里面写上你的子模块。并把它作为一个属性添加到你的主模块中。然后就可以了。

© www.soinside.com 2019 - 2024. All rights reserved.