From f28b08ed654309305960f8f5a882b2f6d492bf1d Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 19:44:51 +0100 Subject: [PATCH] Added relations to RunnerGroup ref #11 --- src/models/GroupContact.ts | 11 +++++++++-- src/models/RunnerGroup.ts | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/models/GroupContact.ts b/src/models/GroupContact.ts index e243d00..3ed4e63 100644 --- a/src/models/GroupContact.ts +++ b/src/models/GroupContact.ts @@ -1,8 +1,15 @@ -import { Entity } from "typeorm"; +import { Entity, OneToMany } from "typeorm"; import { Participant } from "./Participant"; +import { RunnerGroup } from "./RunnerGroup"; /** * Defines a group's contact. */ @Entity() -export class GroupContact extends Participant{} \ No newline at end of file +export class GroupContact extends Participant{ + /** + * Used to link runners to donations. + */ + @OneToMany(() => RunnerGroup, group => group.contact) + groups: RunnerGroup[]; +} \ No newline at end of file diff --git a/src/models/RunnerGroup.ts b/src/models/RunnerGroup.ts index d619e2f..c35ad48 100644 --- a/src/models/RunnerGroup.ts +++ b/src/models/RunnerGroup.ts @@ -1,4 +1,4 @@ -import { PrimaryGeneratedColumn, Column, OneToMany } from "typeorm"; +import { PrimaryGeneratedColumn, Column, OneToMany, ManyToOne } from "typeorm"; import { IsInt, IsNotEmpty, @@ -34,7 +34,7 @@ export abstract class RunnerGroup { */ @Column() @IsOptional() - //TODO: Relationship + @ManyToOne(() => GroupContact, contact => contact.groups) contact?: GroupContact; /**