【问题标题】:the find function in typeorm return field with __underscores__typeorm 中的 find 函数返回带有 __underscores__ 的字段
【发布时间】:2021-01-07 22:59:31
【问题描述】:

我将 typeorm 中的实体定义为:

@Entity('foo', { schema: 'dbo' })
export class Foo extends BaseEntity {

  ...
  @ManyToMany(() => Bar, (bar) => bar.some, { lazy: true })
  bars: Promise<Bar[]>
}

当我使用 find 时,结果显示为下划线,而不是普通对象 (bars):

const results = await Foo.find({ relations: ['bars'] });

results.__bars__ // <--------- this should be just `bars`.

这是 typeorm 的正常行为吗?如果不是如何解决?

【问题讨论】:

    标签: javascript node.js typescript typeorm


    【解决方案1】:

    由于激活延迟加载{ lazy: true }引起的,仅供参考,他们可能会放弃此功能see this,作为解决方案,您可以删除此功能或为结果制作地图。

    PS:即使我尝试了类似的情况并且我什至得到了下划线,我还是通过results.bars得到了bars

    【讨论】:

      猜你喜欢
      • 2015-05-10
      • 1970-01-01
      • 1970-01-01
      • 2022-01-23
      • 2012-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-10
      相关资源
      最近更新 更多