javascript - 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 的正常行为吗?如果不是如何解决?
解决方案
由激活延迟加载引起的{ lazy: true }
,仅供参考,他们可能会放弃此功能,请参阅此,作为解决方案,您可以删除此功能或为结果制作地图。
PS:即使我尝试了类似的情况并且我什至得到了下划线,我还是得到bars
了results.bars
推荐阅读
- elasticsearch - 弹性搜索服务器 7.1 未运行
- neo4j - 获取“neo4j.service:失败,结果为'start-limit-hit'。” 在安装 Neo4j Server 3.5.7
- sql - 如何仅获取最近加入的对?
- python - 拆分熊猫日期时间索引以创建分类变量
- vue.js - 无限滚动实现将数据渲染两次
- python - 加速赛通。列表与 Numpy 数组
- sql - 如何在 SQL 中选择相同属性的 2 个值
- java - 当我尝试获取 swagger.json 时总是得到错误 404
- ruby-on-rails - 如何验证 has_one 关联是否存在?
- google-cloud-platform - 如何在 Google Cloud Platform 上提供以前创建的 Jupyter Notebook