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

162
Views
The one to one relation is undefined typeorm

I'm tryng to use a relations beetenw two tables, but when I create the object it says me I don't have the relations proprieties, so the object "toDelete" ha from proprieties only: { createt_at. updated_at, id, time_spent, } and missing proprieties { user_id, maintance_need_id }

This is my code:

I'm tryng to different ways to recive the info I need.

    const toDelete = await this.maintenanceDoneRepository.findOne(id);

    // const toDelete =await getConnection().createQueryBuilder()
    //     .select("md.maintenance_need_id")
    //     .from(MaintenanceDone, "md")
    //     .where("md.id = :id" ,{id : id})
    //     .getOne();
    
    await getConnection().createQueryBuilder()
        .update(MaintenanceNeed)
        .where("id = :id" ,{ id : toDelete})
        .set({
            is_to_do : true
        })
        .execute();

This is the Entity of both:

@Entity()
export class MaintenanceNeed extends BaseEntity{
    @PrimaryGeneratedColumn({type: 'bigint'})
    id: number;

    @OneToOne(() => Ticket, ticket => ticket.maintenanceNeed, {
        cascade : true
    })
    @JoinColumn({name: 'ticket_id'})
    ticket : Ticket;

    @ManyToOne(()=> House, house => house.maintenanceNeed)
    @JoinColumn({name: 'house_id'})
    house: House;

    @ManyToOne(()=> MaintenanceNeedTemplate, maintenanceNeedTemplate => maintenanceNeedTemplate.maintenanceNeed)
    @JoinColumn({name: 'template_id'})
    maintenanceNeedTemplate : MaintenanceNeedTemplate;

    @OneToOne(()=> MaintenanceDone, maintenanceDone => maintenanceDone.maintenanceNeed)
    maintenanceDone: MaintenanceDone;

    @Column({type: 'boolean', default: true})
    is_to_do: boolean;

}

and the other:

@Entity()
export class MaintenanceDone extends BaseEntity{
   
    @PrimaryGeneratedColumn({type: 'bigint'})
    id: number;

    @ManyToOne(()=> User, user => user.maintenanceDone, {
        onDelete: 'SET NULL'
    })
    @JoinColumn({name: "user_id"})    
    user_id : User;

    @OneToOne(()=> MaintenanceNeed, maintenanceNeed => maintenanceNeed.maintenanceDone)
    @JoinColumn({name: 'maintenance_need_id'})
    maintenanceNeed: MaintenanceNeed;

    @Column({type: "bigint"})
    time_spent: number;
}

Ther rest of the code works really well, and the DB is correct with the columns rigth.

Thanks for any awnser!!

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

0

I solved the problem adding this line .leftJoinAndSelect("md.maintenanceNeed", "maintanceNeed") to the commentented part.

I hope will help someone.

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!