Added relations for runners

ref #11
This commit is contained in:
Nicolai Ort 2020-12-01 19:20:27 +01:00
parent 4075276130
commit a6222a8025
2 changed files with 13 additions and 3 deletions

View File

@ -1,4 +1,4 @@
import { Entity, Column, OneToMany } from "typeorm";
import { Entity, Column, OneToMany, ManyToOne } from "typeorm";
import { IsNotEmpty,} from "class-validator";
import { Participant } from "./Participant";
import { RunnerGroup } from "./RunnerGroup";
@ -14,9 +14,12 @@ export class Runner extends Participant {
*/
@Column()
@IsNotEmpty()
//TODO:Relation
@ManyToOne(() => RunnerGroup, group => group.runners)
group: RunnerGroup;
/**
* Used to link runners to donations.
*/
@OneToMany(() => DistanceDonation, distanceDonation => distanceDonation.runner)
distanceDonations: DistanceDonation[];
}

View File

@ -1,4 +1,4 @@
import { PrimaryGeneratedColumn, Column } from "typeorm";
import { PrimaryGeneratedColumn, Column, OneToMany } from "typeorm";
import {
IsInt,
IsNotEmpty,
@ -6,6 +6,7 @@ import {
IsString,
} from "class-validator";
import { GroupContact } from "./GroupContact";
import { Runner } from "./Runner";
/**
* Defines the runnerGroup interface.
@ -35,4 +36,10 @@ export abstract class RunnerGroup {
@IsOptional()
//TODO: Relationship
contact?: GroupContact;
/**
* Used to link runners to a runner group.
*/
@OneToMany(() => Runner, runner => runner.group)
runners: Runner[];
}