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!!
I solved the problem adding this line .leftJoinAndSelect("md.maintenanceNeed", "maintanceNeed")
to the commentented part.
I hope will help someone.