Skip to content
Advertisement

the find function in typeorm return field with __underscores__

I have entity in typeorm defined as:

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

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

when I using find the results come out with underscore instead the normal object (bars):

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

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

This is normal behavior of typeorm? if not how to fix that?

Advertisement

Answer

That caused by activating lazy loading { lazy: true }, just for your information may they abandoned this feature see this, as a solution may you remove this feature or make a map for the result.

PS: even though I tried the similar case and I even get the underscores, I got the bars by doing results.bars

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement