RenaiApp/src/main/entities/library/world-character.ts

43 lines
1.4 KiB
TypeScript

import { Column, Entity, JoinTable, ManyToMany, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
import { WorkCharacter } from './work-character';
import { World } from './world';
import { WorldCharacterName } from './world-character-name';
/**
* This entity describes a canon character in a fictional world.
*/
@Entity()
export class WorldCharacter
implements IdentifiableEntityInterface, MultiNamedEntityInterface, HierarchicalEntityInterface<WorldCharacter> {
@PrimaryGeneratedColumn()
public id!: number;
@Column({
nullable: false,
default: '',
})
public nameCanonical!: string;
@OneToMany(() => WorldCharacterName, (worldCharacterName: WorldCharacterName) => worldCharacterName.entity)
public names!: Promise<WorldCharacterName[]>;
/**
* the characters in works which are based on this one
*/
@ManyToMany(() => WorkCharacter, (workCharacter: WorkCharacter) => workCharacter.worldCharacters)
public workCharacters!: Promise<WorkCharacter[]>;
/**
* the fictional worlds this character is a part of
*/
@ManyToMany(() => World, (world: World) => world.worldCharacters)
public worlds!: Promise<World[]>;
@ManyToMany(() => WorldCharacter, (worldCharacter: WorldCharacter) => worldCharacter.children)
@JoinTable()
public parents!: Promise<WorldCharacter[]>;
@ManyToMany(() => WorldCharacter, (worldCharacter: WorldCharacter) => worldCharacter.parents)
public children!: Promise<WorldCharacter[]>;
}