import { Column, Entity, ManyToMany, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; import { Author } from './author'; import { AuthorRole } from './author-role'; import { Work } from './work'; /** * This entity connects authors with their work and their role therein. */ @Entity() export class WorkAuthor implements IIdentifiableEntity, IOrderableEntity { @PrimaryGeneratedColumn() public id: number; /** * the work */ @ManyToOne(() => Work, (work: Work) => work.workAuthors, { nullable: false, onDelete: 'CASCADE', onUpdate: 'CASCADE', }) public work: Promise; /** * the roles of the author in the work */ @ManyToMany(() => AuthorRole, (authorRole: AuthorRole) => authorRole.workAuthors) public authorRoles: Promise; /** * the author */ @ManyToOne(() => Author, (author: Author) => author.workAuthors, { nullable: false, onDelete: 'RESTRICT', onUpdate: 'CASCADE', }) public author: Promise; @Column({ nullable: false, default: 0, }) public order: number; }