'Multiple fields OneToOne related to same table - cascade
I was trying few things to use built in feature into TypeORM to remove childs of parent, but without success. Here's table:
@Entity({ name: 'Item' })
export class ItemEntity {
@PrimaryGeneratedColumn()
id: number;
@OneToOne(() => ElementEntity, { cascade: true })
@JoinColumn()
mainElement: ElementEntity;
@OneToOne(() => ElementEntity, { cascade: true })
@JoinColumn()
secondaryElement: ElementEntity;
}
and ElementEntity:
@Entity({ name: 'Element' })
export class ElementEntity {
@PrimaryGeneratedColumn()
public readonly id: number;
@Column()
public readonly name: string;
}
So as you can see there's nothing about Item in Element. And I wanna leave it this way. So for now what I'm doing is removing mainElement and secondaryElement in transaction before removing Item, cause whatever I put into OneToOne options does not work. Pasted without thinking onDelete: 'CASCADE' removedOrphanedRowAction.. nada, does not help here.
Is there some mechanic that will give me possibility to call .remove() on item and TypeORM will take care of its two childs?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
