gpt4 book ai didi

javascript - 带有 __underscores__ 的 typeorm 返回字段中的查找函数

转载 作者:行者123 更新时间:2023-12-05 06:07:02 25 4
gpt4 key购买 nike

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

最佳答案

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

PS:即使我尝试了类似的情况,甚至得到了下划线,我还是通过 results.barsbars 得到了 bars/p>

关于javascript - 带有 __underscores__ 的 typeorm 返回字段中的查找函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65608223/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com