37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { Collection, Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core';
|
|
import { BaseEntity } from '../../../common/entities/base.entity';
|
|
import { Product } from './product.entity';
|
|
import { AttributeValue } from './attribute-value.entity';
|
|
import { FieldType } from 'src/modules/form-builder/interface/print';
|
|
|
|
@Entity({ tableName: 'attributes' })
|
|
export class Attribute extends BaseEntity {
|
|
@ManyToOne(() => Product)
|
|
product!: Product
|
|
|
|
@ManyToOne(() => Attribute, { nullable: true })
|
|
parent?: Attribute | null
|
|
|
|
@OneToMany(() => Attribute, (c) => c.parent)
|
|
children = new Collection<Attribute>(this)
|
|
|
|
@OneToMany(() => AttributeValue, (attrValue) => attrValue.attribute)
|
|
values = new Collection<AttributeValue>(this)
|
|
|
|
@PrimaryKey({ type: 'bigint', autoincrement: true })
|
|
id: bigint;
|
|
|
|
@Property()
|
|
name: string;
|
|
|
|
@Enum(() => FieldType)
|
|
type: FieldType;
|
|
|
|
@Property({ type: 'boolean', default: false })
|
|
isRequired: boolean = false;
|
|
|
|
@Property({ type: 'int', nullable: true })
|
|
order?: number;
|
|
|
|
}
|