fix(backend): Modellering van ManyToMany-relationships verbeterd
This commit is contained in:
		
							parent
							
								
									f4fda7db5d
								
							
						
					
					
						commit
						451ac7546f
					
				
					 6 changed files with 13 additions and 17 deletions
				
			
		|  | @ -18,6 +18,8 @@ export class Group { | |||
| 
 | ||||
|     @ManyToMany({ | ||||
|         entity: () => Student, | ||||
|         owner: true, | ||||
|         inversedBy: "groups" | ||||
|     }) | ||||
|     members!: Student[]; | ||||
|     members: Collection<Student> = new Collection<Student>(this); | ||||
| } | ||||
|  |  | |||
|  | @ -14,9 +14,9 @@ export class Class { | |||
|     @Property({ type: 'string' }) | ||||
|     displayName!: string; | ||||
| 
 | ||||
|     @ManyToMany(() => Teacher) | ||||
|     @ManyToMany({entity: () => Teacher, owner: true, inversedBy: 'classes'}) | ||||
|     teachers!: Collection<Teacher>; | ||||
| 
 | ||||
|     @ManyToMany(() => Student) | ||||
|     @ManyToMany({entity: () => Student, owner: true, inversedBy: 'classes'}) | ||||
|     students!: Collection<Student>; | ||||
| } | ||||
|  |  | |||
|  | @ -8,9 +8,9 @@ import { StudentRepository } from '../../data/users/student-repository.js'; | |||
|     repository: () => StudentRepository, | ||||
| }) | ||||
| export class Student extends User { | ||||
|     @ManyToMany(() => Class) | ||||
|     @ManyToMany({entity: () => Class, mappedBy: 'students'}) | ||||
|     classes!: Collection<Class>; | ||||
| 
 | ||||
|     @ManyToMany(() => Group) | ||||
|     groups!: Collection<Group>; | ||||
|     @ManyToMany({entity: () => Group, mappedBy: 'members'}) | ||||
|     groups: Collection<Group> = new Collection<Group>(this); | ||||
| } | ||||
|  |  | |||
|  | @ -5,6 +5,6 @@ import { TeacherRepository } from '../../data/users/teacher-repository.js'; | |||
| 
 | ||||
| @Entity({ repository: () => TeacherRepository }) | ||||
| export class Teacher extends User { | ||||
|     @ManyToMany(() => Class) | ||||
|     @ManyToMany({entity: () => Class, mappedBy: 'teachers'}) | ||||
|     classes!: Collection<Class>; | ||||
| } | ||||
|  |  | |||
		Reference in a new issue
	
	 Gerald Schmittinger
						Gerald Schmittinger