import { Cascade, Collection, Entity, EntityRepositoryType, Enum, ManyToOne, OneToMany, Property } from "@mikro-orm/core"; import { BaseEntity } from "../../../common/entities/base.entity"; import { Business } from "../../businesses/entities/business.entity"; import { Invoice } from "../../invoices/entities/invoice.entity"; import { BillType } from "../enums/bill-type.enum"; import { BillsRepository } from "../repositories/bill.repository"; @Entity({ repository: () => BillsRepository }) export class Bill extends BaseEntity { @Enum({ items: () => BillType }) type: BillType; @ManyToOne(() => Business, { nullable: false, deleteRule: "cascade" }) business!: Business; @OneToMany(() => Invoice, (invoice) => invoice.bill, { cascade: [Cascade.PERSIST, Cascade.REMOVE], orphanRemoval: true }) invoices = new Collection(this); /** Set by BillsRepository.getBillsList; not persisted. */ @Property({ persist: false }) invoiceCount?: number; [EntityRepositoryType]?: BillsRepository; }