From 40752761302a043e8c974fe98bc57a865eedcb55 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 19:17:53 +0100 Subject: [PATCH] Added relations for participants ref #11 --- src/models/Address.ts | 9 ++++++++- src/models/Participant.ts | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/models/Address.ts b/src/models/Address.ts index df8e2ca..723bac9 100644 --- a/src/models/Address.ts +++ b/src/models/Address.ts @@ -1,4 +1,4 @@ -import { Entity, PrimaryGeneratedColumn, Column } from "typeorm"; +import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from "typeorm"; import { IsInt, IsNotEmpty, @@ -6,6 +6,7 @@ import { IsPostalCode, IsString, } from "class-validator"; +import { Participant } from "./Participant"; /** * Defines a address (to be used for contact information). @@ -70,4 +71,10 @@ export class Address { @IsString() @IsNotEmpty() country: string; + + /** + * Used to link the address to participants. + */ + @OneToMany(() => Participant, participant => participant.address) + participants: Participant[]; } diff --git a/src/models/Participant.ts b/src/models/Participant.ts index 1a8c245..e70e14e 100644 --- a/src/models/Participant.ts +++ b/src/models/Participant.ts @@ -1,4 +1,4 @@ -import { PrimaryGeneratedColumn, Column, OneToMany } from "typeorm"; +import { PrimaryGeneratedColumn, Column, OneToMany, ManyToOne } from "typeorm"; import { IsEmail, IsInt, @@ -53,7 +53,7 @@ export abstract class Participant { */ @Column() @IsOptional() - //TODO: Relationship + @ManyToOne(() => Address, address => address.participants) address?: Address; /**