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

59 lines
1.3 KiB
TypeScript
Raw Normal View History

import { Entity, JoinTable, ManyToMany, OneToMany } from 'typeorm';
import { BaseEntity } from '../base-entity';
import { Author } from './author';
import { MultiName, MultiNamed } from './base/multi-named';
import { Rateable } from './base/rateable';
2019-06-23 15:35:57 +02:00
import { Character } from './character';
import { Copy } from './copy';
2019-06-23 15:35:57 +02:00
import { Fiction } from './fiction';
import { Tag } from './tag';
@Entity()
export class Book extends Rateable(MultiNamed(BaseEntity, 'BookMultiName')) {
2019-11-18 23:00:11 +01:00
@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[]>;
2019-06-23 15:35:57 +02:00
@ManyToMany(() => Fiction, {
nullable: true,
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
})
@JoinTable()
public fictions: Promise<Fiction[]>;
@ManyToMany(() => Character, {
nullable: true,
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
})
@JoinTable()
2019-06-23 15:35:57 +02:00
public characters: Promise<Character[]>;
@ManyToMany(() => Tag, {
nullable: true,
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
})
@JoinTable()
public tags: Promise<Tag[]>;
}
@Entity()
export class BookMultiName extends MultiName('Book') {}