I need to create relations ManyToMany with using third table. Below is my code:
Account.ts
@OneToMany(() => WorkspaceAccount, workspaceAccount => workspaceAccount.accountId, {
cascade: true,
})
workspaces: WorkspaceAccount[];
Workspace.ts
@OneToMany(() => WorkspaceAccount, workspaceAccount => workspaceAccount.workspaceId, {
onUpdate: 'CASCADE', onDelete: 'CASCADE'
})
members: WorkspaceAccount[];
WorkspaceAccount.ts
@ManyToOne(() => Account, {
nullable: false,
onUpdate: 'CASCADE',
onDelete: 'CASCADE',
primary: true,
})
@JoinColumn({
name: 'accountId',
})
accountId: Account;
@ManyToOne(() => Workspace, {
nullable: false,
onUpdate: 'CASCADE',
onDelete: 'CASCADE',
primary: true,
})
@JoinColumn({
name: 'workspaceId',
})
workspaceId: Workspace;
And now I have a question, how to save this relations, in this way, that when I create new Workspace
then automatically will be created object in WorkspaceAccount table?
Thanks for any help