Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
Resultados de TypeORM a indefinidos en la relación OneToOne

Soy nuevo en NestJS (tenía un poco de experiencia en Angular). Me estoy quedando undefined cuando consola. registro una JoinTable (las tablas son nuevas. Tengo la tarea de crear un nuevo microservicio)

Entonces Unit and Hub tiene una relación One to One .

Aquí está la unidad

 @Entity({ name: 'units', }) export class UnitEntity { @PrimaryGeneratedColumn() id: number; @OneToOne(() => HubEntity) @JoinColumn({name: "hub_id"}) hub: HubEntity;

Para su información, también intenté codificarlo así:

 @OneToOne(type => HubEntity, hub => hub.unit) @JoinColumn({name: "hub_id"}) hub: HubEntity;

Para el CENTRO:

 @Entity({ name: 'hubs', }) export class HubEntity { @PrimaryGeneratedColumn() id: number; @OneToOne(type => UnitEntity, unit => unit.hub) @JoinColumn({name: "hub_id"}) unit: UnitEntity;

Para probar, así lo consolé.

 async findAllByUnit(unitId: number) { const unit = await this.unitRepository.findOne(unitId) console.log(unit.hub) }

Devuelve undefined

Por favor, hágame saber lo que me estoy perdiendo.

Gracias de antemano ~

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Tienes que incluir la relación así:

 await this.unitRepository.findOne(unitId, { relations: ['hub'] })
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!