RenaiApp/src/main/entities/library/book.ts

56 lines
1.3 KiB
TypeScript

import { Entity, JoinTable, ManyToMany, OneToMany } from 'typeorm';
import { BaseEntity } from '../base-entity';
import { Author } from './author';
import { MultiNamed } from './base/multi-named';
import { Rateable } from './base/rateable';
import { Character } from './character';
import { Copy } from './copy';
import { Fiction } from './fiction';
import { Tag } from './tag';
@Entity()
export class Book extends Rateable(MultiNamed(BaseEntity)) {
@OneToMany(
() => Copy,
(copy: Copy) => copy.original,
{
nullable: false,
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
}
)
public copies: Promise<Copy[]>;
@ManyToMany(() => Author, {
nullable: true,
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
})
@JoinTable()
public authors: Promise<Author[]>;
@ManyToMany(() => Fiction, {
nullable: true,
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
})
@JoinTable()
public fictions: Promise<Fiction[]>;
@ManyToMany(() => Character, {
nullable: true,
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
})
@JoinTable()
public characters: Promise<Character[]>;
@ManyToMany(() => Tag, {
nullable: true,
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
})
@JoinTable()
public tags: Promise<Tag[]>;
}