I am having issues updating a entity that has a many-to-many reln, curious if I am doing something wrong, or more specifically what is the right way to do this
Consider the following entities ...
@Entity
class Subject
@PrimaryGeneratedColumn('uuid')
id: string;
@Column()
name: string;
@ManyToMany(() => Note, note => note.subjects)
@JoinTable()
notes: Note[];
...
@Entity()
export class Note {
@PrimaryGeneratedColumn('uuid')
id: string;
@ManyToMany(() => Subject, (subject: Subject) => subject.notes)
subjects: Subject[];
In my code I find the node and then try to update it and save like so ...
const note = await noteRepo.findOneOrFail(noteId);
const foundSubjects = await subjectRepo.findByIds(Array.from(subjectIds));
note.subjects = foundSubjects;
noteRepo.save(note);
But alas, the subjects are not saved on the note.
What is the right way to do this?
Thanks!