Skip to content

Correct use of ManyToMany relations #261

Closed Answered by integrITsolutions
integrITsolutions asked this question in Q&A
Discussion options

You must be logged in to vote

Finally managed to map the relation correctly by using a custom hook 🌈

The issue is that I receive an array of participantIds and first need to fetch the participants based on these ids, for TypeORM to be able to make the proper relation in the JoinTable.

This is done now by defining the ManyToMany relation in the Event entity like this:

@JoinTable({
    name: 'event_participants',
    joinColumn: {
      name: 'event_id',
      referencedColumnName: 'id',
    },
    inverseJoinColumn: {
      name: 'participant_id',
      referencedColumnName: 'id',
    },
  })
  participants: User[];

Defining a custom hook event-participant.hook.ts, which catches the mutation and fetches the correspond…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@integrITsolutions
Comment options

@TriPSs
Comment options

@integrITsolutions
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by integrITsolutions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants