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

144
Views
TypeORM results to undefined on OneToOne relationship

I'm new to NestJS (I had a bit of experience in Angular). I'm getting undefined when I console.log a JoinTable (the tables are new. I'm tasked to create a new microservice)

So Unit and Hub has One to One relationship.

Here is the unit

  @Entity({
    name: 'units',
  })
  export class UnitEntity {
    @PrimaryGeneratedColumn()
    id: number;

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

FYI I also tried coding it like this:

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

For the HUB:

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

For testing, this is how I consoled it.

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

    console.log(unit.hub)
  }

It returns undefined

Please let me know what I'm missing.

Thank you in advance~

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

0

You have to include the relationship like this:

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!