Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

163
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda