首页 > 解决方案 > typeorm 中的 find 函数返回带有 __underscores__ 的字段

问题描述

我在 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 的正常行为吗?如果不是如何解决?

标签: javascriptnode.jstypescripttypeorm

解决方案


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

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


推荐阅读