import { Collection, Entity, Enum, ManyToOne, OneToMany, OptionalProps, PrimaryKey, Property } from '@mikro-orm/core'; import { FieldOption } from './field-option.entity'; import { EntityType, FieldType } from '../interface/print'; import { BaseEntity } from 'src/common/entities/base.entity'; @Entity({ tableName: 'field' }) export class Field extends BaseEntity { [OptionalProps]?: 'createdAt' | 'deletedAt' @OneToMany(() => FieldOption, (attrValue) => attrValue.field) options = new Collection(this) // Discriminator column @Enum(() => EntityType) // Product , Print entityType: EntityType; // Foreign key based on entityType @Property({ type: 'string',columnType:'char(26)' }) entityId: string; @Property() name: string; @Enum(() => FieldType) type: FieldType; @Property({ type: 'boolean', default: false }) isRequired: boolean = false; @Property({ type: 'boolean', default: false }) multiple: boolean = false; @Property({ type: 'int', nullable: true }) order?: number; }