Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

166
Views
How to save ManyToMany relations in TypeORM?

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

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!