UNPKG

undeexcepturi

Version:

TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.

44 lines (33 loc) 720 B
import { EagerProps, Entity, Index, ManyToOne, OneToOne, PrimaryKey, Property, Ref, SerializedPrimaryKey, } from '@mikro-orm/core'; import { ObjectId } from 'bson'; import { Book } from './Book'; import FooBar from './FooBar'; @Entity() export class FooBaz { [EagerProps]?: 'bar' | 'book'; @PrimaryKey() _id!: ObjectId; @SerializedPrimaryKey() id!: string; @Property() @Index() name!: string; @OneToOne(() => FooBar, bar => bar.baz, { eager: true, ref: true }) bar!: Ref<FooBar>; @ManyToOne(() => Book, { eager: true, nullable: true, ref: true }) book?: Ref<Book>; static create(name: string) { const baz = new FooBaz(); baz.name = name; return baz; } }