diff --git a/src/models/Donation.ts b/src/models/Donation.ts index 87f4e80..f7ea19c 100644 --- a/src/models/Donation.ts +++ b/src/models/Donation.ts @@ -1,4 +1,4 @@ -import { PrimaryGeneratedColumn, Column } from "typeorm"; +import { PrimaryGeneratedColumn, Column, ManyToOne } from "typeorm"; import { IsInt, IsNotEmpty, @@ -24,7 +24,7 @@ export abstract class Donation { */ @Column() @IsNotEmpty() - //TODO: Relationship + @ManyToOne(() => Participant, donor => donor.donations) donor: Participant; /** diff --git a/src/models/Participant.ts b/src/models/Participant.ts index 2b356a3..1a8c245 100644 --- a/src/models/Participant.ts +++ b/src/models/Participant.ts @@ -1,4 +1,4 @@ -import { PrimaryGeneratedColumn, Column } from "typeorm"; +import { PrimaryGeneratedColumn, Column, OneToMany } from "typeorm"; import { IsEmail, IsInt, @@ -8,6 +8,7 @@ import { IsString, } from "class-validator"; import { Address } from "./Address"; +import { Donation } from "./Donation"; /** * Defines the participant interface. @@ -72,4 +73,10 @@ export abstract class Participant { @IsOptional() @IsEmail() email?: string; + + /** + * Used to link the participant as the donor of a donation. + */ + @OneToMany(() => Donation, donation => donation.donor) + donations: Donation[]; } \ No newline at end of file