◾️ CASCADE: if user is deleted, delete all related order info
@Entity()
export class Order extends CoreEntity {
@Field((type) => User)
@ManyToOne((type) => User, (user) => user.orders, {
onDelete: 'CASCADE',
})
customer: User;
}
◾️ SET NULL: if user is deleted, do not delete the related order info
export class Order extends CoreEntity {
@Field((type) => User, { nullable: true })
@ManyToOne((type) => User, (user) => user.orders, {
onDelete: 'SET NULL',
nullable: true,
})
customer?: User;